|
| 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 | + |
| 7 | + <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%2224px%22%20viewBox%3D%220%20-960%20960%20960%22%20width%3D%2224px%22%20fill%3D%22%23e3e3e3%22%3E%3Cpath%20d%3D%22M200-80q-33%200-56.5-23.5T120-160v-560q0-33%2023.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33%200%2056.5%2023.5T840-720v560q0%2033-23.5%2056.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0%2000v-80%2080Zm280%20240q-17%200-28.5-11.5T440-440q0-17%2011.5-28.5T480-480q17%200%2028.5%2011.5T520-440q0%2017-11.5%2028.5T480-400Zm-160%200q-17%200-28.5-11.5T280-440q0-17%2011.5-28.5T320-480q17%200%2028.5%2011.5T360-440q0%2017-11.5%2028.5T320-400Zm320%200q-17%200-28.5-11.5T600-440q0-17%2011.5-28.5T640-480q17%200%2028.5%2011.5T680-440q0%2017-11.5%2028.5T640-400ZM480-240q-17%200-28.5-11.5T440-280q0-17%2011.5-28.5T480-320q17%200%2028.5%2011.5T520-280q0%2017-11.5%2028.5T480-240Zm-160%200q-17%200-28.5-11.5T280-280q0-17%2011.5-28.5T320-320q17%200%2028.5%2011.5T360-280q0%2017-11.5%2028.5T320-240Zm320%200q-17%200-28.5-11.5T600-280q0-17%2011.5-28.5T640-320q17%200%2028.5%2011.5T680-280q0%2017-11.5%2028.5T640-240Z%22/%3E%3C/svg%3E"> |
| 8 | + |
| 9 | + <title>Swedish Calendar</title> |
| 10 | + |
| 11 | + <style> |
| 12 | + |
| 13 | + body {font-family:arial;} |
| 14 | + |
| 15 | + a, a:visited {color:#000;} |
| 16 | + |
| 17 | + table { |
| 18 | + border-collapse: collapse; |
| 19 | + width: 100%; |
| 20 | + max-width: 100%; |
| 21 | + table-layout: fixed; |
| 22 | + } |
| 23 | + |
| 24 | + th, td { |
| 25 | + border: 1px solid #ddd; |
| 26 | + padding: 3pt; |
| 27 | + height: 28pt; |
| 28 | + vertical-align: middle; |
| 29 | + } |
| 30 | + |
| 31 | + td { |
| 32 | + overflow: hidden; |
| 33 | + text-overflow: ellipsis; |
| 34 | + white-space: nowrap; |
| 35 | + font-size:10pt; |
| 36 | + } |
| 37 | + |
| 38 | + th { |
| 39 | + background-color: #f4f4f4; |
| 40 | + width: 30pt; /* Allows headers to size naturally */ |
| 41 | + white-space: normal; /* Allows wrapping if needed */ |
| 42 | + } |
| 43 | + |
| 44 | + @media print { |
| 45 | + .no-print { |
| 46 | + display: none; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | +</style> |
| 51 | + |
| 52 | +</head> |
| 53 | +<body> |
| 54 | + |
| 55 | +<script async type = "text/javascript" src = "https://cdn.jsdelivr.net/npm/php-wasm/php-tags.jsdelivr.mjs"></script> |
| 56 | + |
| 57 | + <div id="output"></div> |
| 58 | + <div id="input" style="display:none;"></div> |
| 59 | + |
| 60 | + |
| 61 | + <script> |
| 62 | + const year = new URLSearchParams(window.location.search).get("year"); |
| 63 | + document.getElementById("input").innerHTML = year; |
| 64 | + </script> |
| 65 | + |
| 66 | + <script type = "text/php" data-stdout = "#output" data-stdin = "#input"> |
| 67 | + |
| 68 | + <?php |
| 69 | + |
| 70 | + //setlocale(LC_ALL, 'sv_SE.UTF-8'); |
| 71 | + |
| 72 | + $year = file_get_contents('php://stdin'); |
| 73 | + |
| 74 | + if ( $year == "" ) { $year = (new DateTime("$year-01-05"))->format("Y"); } |
| 75 | + |
| 76 | + echo '<div class="no-print">'; |
| 77 | + $currYear = (new DateTime())->format("Y"); |
| 78 | + echo '<a href="?year='.$currYear.'">'.$currYear.'</a>'; |
| 79 | + $nextYear = (new DateTime())->modify('+1 year')->format("Y"); |
| 80 | + echo ' <a href="?year='.$nextYear.'">'.$nextYear.'</a>'; |
| 81 | + $nextNextYear = (new DateTime())->modify('+2 year')->format("Y"); |
| 82 | + echo ' <a href="?year='.$nextNextYear.'">'.$nextNextYear.'</a>'; |
| 83 | + echo '</div>'; |
| 84 | + |
| 85 | + echo '<h1>Svenska ledighetskalendern '.$year.'</h1>'; |
| 86 | + |
| 87 | + // RANGE |
| 88 | + |
| 89 | + // First week of year |
| 90 | + $jan1 = new DateTime("$year-01-01"); |
| 91 | + $jan1->modify('monday this week'); |
| 92 | + |
| 93 | + // Last week of year |
| 94 | + $dec31 = new DateTime("$year-12-31"); |
| 95 | + $dec31->modify('sunday this week'); |
| 96 | + |
| 97 | + // HOLIDAYS |
| 98 | + |
| 99 | + // Epiphany |
| 100 | + $epiphanyEve = (new DateTime("$year-01-05"))->format("Y-m-d"); |
| 101 | + $epiphanyDay = (new DateTime("$year-01-06"))->format("Y-m-d"); |
| 102 | + |
| 103 | + // Easter |
| 104 | + $base = new DateTime("$year-03-21"); |
| 105 | + $days = easter_days($year); |
| 106 | + $easterSunday = $base->modify("+$days days")->format("Y-m-d"); |
| 107 | + |
| 108 | + $goodFriday = new DateTime($easterSunday); |
| 109 | + $goodFriday = $goodFriday->modify('-2 days')->format("Y-m-d"); |
| 110 | + |
| 111 | + $easterGreen1 = new DateTime($easterSunday); |
| 112 | + $easterGreen1 = $easterGreen1->modify('-3 days')->format("Y-m-d"); |
| 113 | + $easterGreen2 = new DateTime($easterSunday); |
| 114 | + $easterGreen2 = $easterGreen2->modify('-4 days')->format("Y-m-d"); |
| 115 | + $easterGreen3 = new DateTime($easterSunday); |
| 116 | + $easterGreen3 = $easterGreen3->modify('-5 days')->format("Y-m-d"); |
| 117 | + $easterGreen4 = new DateTime($easterSunday); |
| 118 | + $easterGreen4 = $easterGreen4->modify('-6 days')->format("Y-m-d"); |
| 119 | + |
| 120 | + $easterMonday = new DateTime($easterSunday); |
| 121 | + $easterMonday = $easterMonday->modify('+1 days')->format("Y-m-d"); |
| 122 | + |
| 123 | + // Walpurgis Night |
| 124 | + $walpurgisNight = (new DateTime("$year-04-30"))->format("Y-m-d"); |
| 125 | + $may1 = (new DateTime("$year-05-01"))->format("Y-m-d"); |
| 126 | + |
| 127 | + // Feast of the Ascension |
| 128 | + $feastAscension = (new DateTime($easterSunday))->modify("+39 days")->format("Y-m-d"); |
| 129 | + |
| 130 | + // National Day |
| 131 | + $june6 = (new DateTime("$year-06-06"))->format("Y-m-d"); |
| 132 | + |
| 133 | + // Midsummer |
| 134 | + // Midsummer: Find June 19 of the given year |
| 135 | + $midsummerStart = new DateTime("$year-06-19"); |
| 136 | + // Find the first Friday on or after June 19 |
| 137 | + while ($midsummerStart->format("N") != 5) { // 5 = Friday |
| 138 | + $midsummerStart->modify('+1 day'); |
| 139 | + } |
| 140 | + $midsummerEve = $midsummerStart->format("Y-m-d"); |
| 141 | + $midsummerDay = $midsummerStart->modify('+1 day')->format("Y-m-d"); |
| 142 | + |
| 143 | + // Christmas |
| 144 | + $christmasEve = (new DateTime("$year-12-24"))->format("Y-m-d"); |
| 145 | + $christmasDay = (new DateTime("$year-12-25"))->format("Y-m-d"); |
| 146 | + $boxingDay = (new DateTime("$year-12-26"))->format("Y-m-d"); |
| 147 | + |
| 148 | + // New year |
| 149 | + $newYearsEve = (new DateTime("$year-12-31"))->format("Y-m-d"); |
| 150 | + $newYearsDay = (new DateTime("$year-12-31"))->modify('+1 day')->format("Y-m-d"); |
| 151 | + |
| 152 | + // HOLIDAY ARRAYS |
| 153 | + |
| 154 | + $holidayArray = [ |
| 155 | + [$epiphanyEve, "Trettondagsafton"], |
| 156 | + [$epiphanyDay, "Trettondagen"], |
| 157 | + [$goodFriday, "Långfredagen"], |
| 158 | + [$easterSunday, "Påskdagen"], |
| 159 | + [$easterMonday, "Annandag Påsk"], |
| 160 | + [$feastAscension, "Kristi Himmelsfärdsdag"], |
| 161 | + [$may1, "Första Maj"], |
| 162 | + [$june6, "Sveriges nationaldag"], |
| 163 | + [$midsummerEve, "Midsommarafton"], |
| 164 | + [$midsummerDay, "Midsommardagen"], |
| 165 | + [$christmasEve, "Julafton"], |
| 166 | + [$christmasDay, "Juldagen"], |
| 167 | + [$boxingDay, "Annandag Jul"], |
| 168 | + [$newYearsEve, "Nyårsafton"], |
| 169 | + [$newYearsDay, "Nyårsdagen"] |
| 170 | + ]; |
| 171 | + |
| 172 | + $greenDaysArray = [ |
| 173 | + [$easterGreen1, "Påskveckan"], |
| 174 | + [$easterGreen2, "Påskveckan"], |
| 175 | + [$easterGreen3, "Påskveckan"], |
| 176 | + [$easterGreen4, "Skärtorsdagen"], |
| 177 | + [$walpurgisNight, "Valborgsmässoafton"] |
| 178 | + ]; |
| 179 | + |
| 180 | + // DRAW CALENDAR |
| 181 | + |
| 182 | + $dateArray = []; |
| 183 | + $currentDate = clone $jan1; |
| 184 | + |
| 185 | + while ($currentDate <= $dec31) { |
| 186 | + $dateArray[] = $currentDate->format("Y-m-d"); |
| 187 | + $currentDate->modify('+1 day'); |
| 188 | + } |
| 189 | + |
| 190 | + // Chunk the dates array into pieces of 7 days |
| 191 | + $chunkedDates = array_chunk($dateArray, 7); |
| 192 | + |
| 193 | + echo '<table style="">'; |
| 194 | + |
| 195 | + foreach ($chunkedDates as $index => $chunk) { |
| 196 | + echo "<tr>"; |
| 197 | + $weekNumber = (new DateTime($chunk[0]))->format("W"); |
| 198 | + echo '<th style="background-color:#ccc;">'.$weekNumber.'</th>'; |
| 199 | + |
| 200 | + foreach ($chunk as $date) { |
| 201 | + |
| 202 | + $index = array_search($date, array_column($holidayArray, 0)); |
| 203 | + $color = ""; |
| 204 | + $holidayName = ""; |
| 205 | + $indexGreen = array_search($date, array_column($greenDaysArray, 0)); |
| 206 | + $greenName = ""; |
| 207 | + |
| 208 | + if ( (new DateTime($date))->format("N") == "6" || (new DateTime($date))->format("N") == "7" ) { |
| 209 | + $color = "background-color:#eee;"; |
| 210 | + if ( (new DateTime($date))->format("N") == "7" ) { $color .= "color:#EE4B2B;"; } |
| 211 | + } else if ( $index !== false ) { |
| 212 | + $color = "background-color:#FFCCCB;"; |
| 213 | + $holidayName = $holidayArray[$index][1]; |
| 214 | + } else if ( $indexGreen !== false ) { |
| 215 | + $color = "background-color:#C1E1C1;"; |
| 216 | + $greenName = $greenDaysArray[$indexGreen][1]; |
| 217 | + } else if ( (new DateTime($date))->format("W") == "9" || (new DateTime($date))->format("W") == "44" ) { |
| 218 | + $color = "background-color:#C1E1C1;"; |
| 219 | + } else { |
| 220 | + $color = ""; |
| 221 | + } |
| 222 | + $string = strtolower((new DateTime($date))->format("d M")); |
| 223 | + $string = str_replace("oct", "okt", $string); |
| 224 | + $string = str_replace("y", "j", $string); |
| 225 | + echo '<td style="'.$color.'">'.$string.' '.$holidayName.' '.$greenName.'</td>'; |
| 226 | + } |
| 227 | + echo "</tr>"; |
| 228 | + } |
| 229 | + |
| 230 | + echo '</table>'; |
| 231 | + |
| 232 | +</script> |
| 233 | + |
| 234 | + |
| 235 | +</body> |
| 236 | +</html> |
0 commit comments