diff --git a/docs/calendar.html b/docs/calendar.html index 5d9a44b..0c19ed7 100644 --- a/docs/calendar.html +++ b/docs/calendar.html @@ -4,7 +4,7 @@ Bikram Calendar - + @@ -332,8 +346,13 @@

विक्रम सम्बत क्यालेण्डर

const defaultLanguage = "nepali"; const monthName = getMonthNameWithDefaultLanguage(month, defaultLanguage); + const gregorianStart = getGregorianDate(year, month, 1); + const gregorianEnd = getLastDayOfGregorian(year, month); + + const gregorianMonthDisplay = formatGregorianMonthDisplay(gregorianStart, gregorianEnd); + - let calendarHTML = `

${monthName} ${convertToDevanagari(year)}

`; + let calendarHTML = `

${monthName} ${convertToDevanagari(year)} ${gregorianMonthDisplay}

`; const weekdays = ['आइतवार', 'सोमवार', 'मङ्गलवार', 'बुधवार', 'बिहीवार', 'शुक्रवार', 'शनिवार']; // Nepali weekdays @@ -529,6 +548,40 @@

विक्रम सम्बत क्यालेण्डर

generateCalendar(currentYear, currentMonth); } + function getGregorianDate(year, month, day) { + const bikram = new Bikram(); + return bikram.toGregorian(year, month, day); +} + +function getLastDayOfGregorian(year, month) { + const bikram = new Bikram(); + const nextMonthFirstDay = bikram.toGregorian(year, month + 1, 1); + const lastDayOfMonth = new Date(nextMonthFirstDay.year, nextMonthFirstDay.month - 1, nextMonthFirstDay.day - 1); + return { + day: lastDayOfMonth.getDate(), + month: lastDayOfMonth.getMonth() + 1, // months are 0-indexed in JavaScript Date + year: lastDayOfMonth.getFullYear() + }; +} + +function getGregorianMonthName(month) { + const gregorianMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; + return gregorianMonths[month - 1]; +} + +function formatGregorianMonthDisplay(gregorianStart, gregorianEnd) { + if (gregorianStart.year === gregorianEnd.year) { + if (gregorianStart.month === gregorianEnd.month) { + return `${gregorianStart.year} ${getGregorianMonthName(gregorianStart.month)}`; + } else { + return `${gregorianStart.year} ${getGregorianMonthName(gregorianStart.month)}/${getGregorianMonthName(gregorianEnd.month)}`; + } + } else { + return `${gregorianStart.year}/${gregorianEnd.year} ${getGregorianMonthName(gregorianStart.month)}/${getGregorianMonthName(gregorianEnd.month)}`; + } +} + + window.onload = showCurrentMonth;