|  | 
|  | 1 | +<!DOCTYPE html> | 
|  | 2 | +<html lang="en"> | 
|  | 3 | +<head> | 
|  | 4 | +    <meta charset="UTF-8"> | 
|  | 5 | +    <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 
|  | 6 | +    <title>Bikram Calendar</title> | 
|  | 7 | +    <link href="https://fonts.googleapis.com/css2?family=Eczar:wght@400;500&display=swap" rel="stylesheet"> | 
|  | 8 | +    <script type="text/javascript" src="bikram.js"></script> | 
|  | 9 | +    <style> | 
|  | 10 | +        body { | 
|  | 11 | +            font-family: Eczar, sans-serif; | 
|  | 12 | +            margin: 20px; | 
|  | 13 | +        } | 
|  | 14 | +        table { | 
|  | 15 | +            width: 100%; | 
|  | 16 | +            border-collapse: collapse; | 
|  | 17 | +            margin-top: 20px; | 
|  | 18 | +        } | 
|  | 19 | +        th, td { | 
|  | 20 | +            border: 1px solid #ddd; | 
|  | 21 | +            padding: 10px; | 
|  | 22 | +            text-align: center; | 
|  | 23 | +        } | 
|  | 24 | +        th { | 
|  | 25 | +            background-color: #007bff; | 
|  | 26 | +            color: white; | 
|  | 27 | +        } | 
|  | 28 | +        .today { | 
|  | 29 | +            background-color: green; | 
|  | 30 | +            color: white; | 
|  | 31 | +        } | 
|  | 32 | +        .navigation { | 
|  | 33 | +            margin: 20px 0; | 
|  | 34 | +        } | 
|  | 35 | +        .navigation button { | 
|  | 36 | +            padding: 10px; | 
|  | 37 | +            margin: 0 5px; | 
|  | 38 | +            cursor: pointer; | 
|  | 39 | +        } | 
|  | 40 | +    </style> | 
|  | 41 | +</head> | 
|  | 42 | +<body> | 
|  | 43 | +    <div class="container"> | 
|  | 44 | +        <h1>Bikram Calendar</h1> | 
|  | 45 | +        <div id="calendar"></div> | 
|  | 46 | +    </div> | 
|  | 47 | +    <div > | 
|  | 48 | +        <p>Note: calendar is not well tested yet. need to add more functionality like navigation, event handling etc.</p> | 
|  | 49 | +    </div> | 
|  | 50 | +    <script> | 
|  | 51 | +        let currentYear; | 
|  | 52 | +        let currentMonth; | 
|  | 53 | +        let currentDay; | 
|  | 54 | + | 
|  | 55 | +        function showCurrentMonth() { | 
|  | 56 | +            const today = new Date(); | 
|  | 57 | +            const bikram = new Bikram(); | 
|  | 58 | +            bikram.fromGregorian(today.getFullYear(), today.getMonth() + 1, today.getDate()); | 
|  | 59 | +             | 
|  | 60 | +            currentYear = bikram.getYear(); | 
|  | 61 | +            currentMonth = bikram.getMonth(); | 
|  | 62 | +            currentDay = bikram.getDay(); | 
|  | 63 | + | 
|  | 64 | +            generateCalendar(currentYear, currentMonth); | 
|  | 65 | +        } | 
|  | 66 | + | 
|  | 67 | +        function generateCalendar(year, month) { | 
|  | 68 | +            const calendarDiv = document.getElementById('calendar'); | 
|  | 69 | +            calendarDiv.innerHTML = ''; | 
|  | 70 | + | 
|  | 71 | +            const daysInMonth = new Bikram().daysInMonth(year, month); | 
|  | 72 | +            const bikram = new Bikram(); | 
|  | 73 | +            | 
|  | 74 | +            const today = new Date(); | 
|  | 75 | +            const todayBikram = new Bikram(); | 
|  | 76 | +            todayBikram.fromGregorian(today.getFullYear(), today.getMonth() + 1, today.getDate()); | 
|  | 77 | +            const todayBikramYear = todayBikram.getYear(); | 
|  | 78 | +            const todayBikramMonth = todayBikram.getMonth(); | 
|  | 79 | +            const todayBikramDay = todayBikram.getDay(); | 
|  | 80 | + | 
|  | 81 | +            const defaultLanguage = "nepali"; | 
|  | 82 | +            const monthName = getMonthNameWithDefaultLanguage(month, defaultLanguage); | 
|  | 83 | +             | 
|  | 84 | +            let calendarHTML = `<h2>${monthName} ${year}</h2><table><tr>`; | 
|  | 85 | +             | 
|  | 86 | +            const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; | 
|  | 87 | +            weekdays.forEach(day => { | 
|  | 88 | +                calendarHTML += `<th>${day}</th>`; | 
|  | 89 | +            }); | 
|  | 90 | +            calendarHTML += '</tr><tr>'; | 
|  | 91 | + | 
|  | 92 | +            const firstGregorianDate = new Date(year, month - 1, 1); | 
|  | 93 | +            const firstDay = firstGregorianDate.getDay(); | 
|  | 94 | +            const adjustedFirstDay = (firstDay + 1) % 7; | 
|  | 95 | + | 
|  | 96 | +            for (let i = 0; i < adjustedFirstDay; i++) { | 
|  | 97 | +                calendarHTML += '<td></td>'; | 
|  | 98 | +            } | 
|  | 99 | + | 
|  | 100 | +            for (let day = 1; day <= daysInMonth; day++) { | 
|  | 101 | +                const isToday = (day === todayBikramDay && month === todayBikramMonth && year === todayBikramYear); | 
|  | 102 | +                const className = isToday ? 'today' : ''; | 
|  | 103 | + | 
|  | 104 | +                calendarHTML += `<td class="${className}">${day}</td>`; | 
|  | 105 | +                if ((day + adjustedFirstDay) % 7 === 0) { | 
|  | 106 | +                    calendarHTML += '</tr><tr>'; | 
|  | 107 | +                } | 
|  | 108 | +            } | 
|  | 109 | + | 
|  | 110 | +            calendarHTML += '</tr></table>'; | 
|  | 111 | +            calendarDiv.innerHTML = calendarHTML; | 
|  | 112 | +        } | 
|  | 113 | + | 
|  | 114 | +        function getMonthNameWithDefaultLanguage(month, language) { | 
|  | 115 | +            const bikram = new Bikram(); | 
|  | 116 | +            const originalGetMonthName = bikram.getMonthName.bind(bikram); | 
|  | 117 | +            bikram.getMonthName = function(month) { | 
|  | 118 | +                    const nepaliMonths = ["बैसाख", "जेष्ठ", "आषाढ", "श्रावण", "भाद्र", "आश्विन", "कार्तिक", "मंसिर", "पौष", "माघ", "फागुन", "चैत"]; | 
|  | 119 | +                    return nepaliMonths[month - 1]; | 
|  | 120 | +                } | 
|  | 121 | +             | 
|  | 122 | + | 
|  | 123 | +            const monthName = bikram.getMonthName(month); | 
|  | 124 | + | 
|  | 125 | +            return monthName; | 
|  | 126 | +        } | 
|  | 127 | + | 
|  | 128 | +        window.onload = showCurrentMonth; | 
|  | 129 | +    </script> | 
|  | 130 | +</body> | 
|  | 131 | +</html> | 
0 commit comments