| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | require_once 'Date/Holidays/Driver.php'; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class Date_Holidays_Driver_Japanese extends Date_Holidays_Driver |
|---|
| 42 | { |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | function Date_Holidays_Driver_Japanese() |
|---|
| 52 | { |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | function _buildHolidays() |
|---|
| 63 | { |
|---|
| 64 | parent::_buildHolidays(); |
|---|
| 65 | |
|---|
| 66 | $this->_buildNewYearsDay(); |
|---|
| 67 | $this->_buildComingofAgeDay(); |
|---|
| 68 | $this->_buildNationalFoundationDay(); |
|---|
| 69 | $this->_buildVernalEquinoxDay(); |
|---|
| 70 | $this->_buildShowaDay(); |
|---|
| 71 | $this->_buildConstitutionMemorialDay(); |
|---|
| 72 | $this->_buildGreeneryDay(); |
|---|
| 73 | $this->_buildChildrensDay(); |
|---|
| 74 | $this->_buildMarineDay(); |
|---|
| 75 | $this->_buildRespectfortheAgedDay(); |
|---|
| 76 | $this->_buildAutumnalEquinoxDay(); |
|---|
| 77 | $this->_buildHealthandSportsDay(); |
|---|
| 78 | $this->_buildNationalCultureDay(); |
|---|
| 79 | $this->_buildLaborThanksgivingDay(); |
|---|
| 80 | $this->_buildEmperorsBirthday(); |
|---|
| 81 | |
|---|
| 82 | $this->_buildOtherMemorialDays(); |
|---|
| 83 | |
|---|
| 84 | $this->_buildSubstituteHolidays(); |
|---|
| 85 | |
|---|
| 86 | return true; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | function getISO3166Codes() |
|---|
| 98 | { |
|---|
| 99 | return array('jp', 'jpn'); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | function _buildNewYearsDay() |
|---|
| 108 | { |
|---|
| 109 | if ($this->_year >= 1949) { |
|---|
| 110 | $this->_addHoliday('newYearsDay', |
|---|
| 111 | $this->_year . '-01-01', |
|---|
| 112 | 'New Year\'s Day'); |
|---|
| 113 | } |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | function _buildComingofAgeDay() |
|---|
| 122 | { |
|---|
| 123 | $date = null; |
|---|
| 124 | if ($this->_year >= 2000) { |
|---|
| 125 | $date = $this->_calcNthMondayInMonth(1, 2); |
|---|
| 126 | } else if ($this->_year >= 1949) { |
|---|
| 127 | $date = $this->_year . '-01-15'; |
|---|
| 128 | } |
|---|
| 129 | if (!is_null($date)) { |
|---|
| 130 | $this->_addHoliday('comingOfAgeDay', |
|---|
| 131 | $date, |
|---|
| 132 | 'Coming of Age Day'); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | function _buildNationalFoundationDay() |
|---|
| 142 | { |
|---|
| 143 | if ($this->_year >= 1949) { |
|---|
| 144 | $this->_addHoliday('nationalFoundationDay', |
|---|
| 145 | $this->_year . '-02-11', |
|---|
| 146 | 'National Foundation Day'); |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | function _buildVernalEquinoxDay() |
|---|
| 156 | { |
|---|
| 157 | $day = null; |
|---|
| 158 | if ($this->_year >= 1948 && $this->_year <= 1979) { |
|---|
| 159 | $day = floor(20.8357 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 160 | } else if ($this->_year <= 2099) { |
|---|
| 161 | $day = floor(20.8431 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 162 | } else if ($this->_year <= 2150) { |
|---|
| 163 | $day = floor(21.8510 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 164 | } |
|---|
| 165 | if (!is_null($day)) { |
|---|
| 166 | $this->_addHoliday('Vernal Equinox Day', |
|---|
| 167 | sprintf('%04d-%02d-%02d', $this->_year, 3, $day), |
|---|
| 168 | 'Vernal Equinox Day'); |
|---|
| 169 | } |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | function _buildShowaDay() |
|---|
| 178 | { |
|---|
| 179 | $name = null; |
|---|
| 180 | if ($this->_year >= 2007) { |
|---|
| 181 | $name = 'Showa Day'; |
|---|
| 182 | } else if ($this->_year >= 1989) { |
|---|
| 183 | $name = 'Greenery Day'; |
|---|
| 184 | } else if ($this->_year >= 1949) { |
|---|
| 185 | $name = 'Showa Emperor\'s Birthday'; |
|---|
| 186 | } |
|---|
| 187 | if (!is_null($name)) { |
|---|
| 188 | $this->_addHoliday('showaDay', |
|---|
| 189 | $this->_year . '-04-29', |
|---|
| 190 | $name); |
|---|
| 191 | } |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | function _buildConstitutionMemorialDay() |
|---|
| 200 | { |
|---|
| 201 | if ($this->_year >= 1949) { |
|---|
| 202 | $this->_addHoliday('constitutionMemorialDay', |
|---|
| 203 | $this->_year . '-05-03', |
|---|
| 204 | 'Constitution Memorial Day'); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | function _buildGreeneryDay() |
|---|
| 214 | { |
|---|
| 215 | $name = null; |
|---|
| 216 | if ($this->_year >= 2007) { |
|---|
| 217 | $name = 'Greenery Day'; |
|---|
| 218 | } else if ($this->_year >= 1986) { |
|---|
| 219 | $date =& new Date($this->_year . '-05-04'); |
|---|
| 220 | if ($date->getDayOfWeek() != 0) { |
|---|
| 221 | $name = 'National Holiday'; |
|---|
| 222 | } |
|---|
| 223 | } |
|---|
| 224 | if (!is_null($name)) { |
|---|
| 225 | $this->_addHoliday('greeneryDay', |
|---|
| 226 | $this->_year . '-05-04', |
|---|
| 227 | $name); |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | function _buildChildrensDay() |
|---|
| 237 | { |
|---|
| 238 | if ($this->_year >= 1949) { |
|---|
| 239 | $this->_addHoliday('childrensDay', |
|---|
| 240 | $this->_year . '-05-05', |
|---|
| 241 | 'Children\'s Day'); |
|---|
| 242 | } |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | function _buildMarineDay() |
|---|
| 251 | { |
|---|
| 252 | $date = null; |
|---|
| 253 | if ($this->_year >= 2003) { |
|---|
| 254 | $date = $this->_calcNthMondayInMonth(7, 3); |
|---|
| 255 | } else if ($this->_year >= 1996) { |
|---|
| 256 | $date = $this->_year . '-07-20'; |
|---|
| 257 | } |
|---|
| 258 | if (!is_null($date)) { |
|---|
| 259 | $this->_addHoliday('marineDay', |
|---|
| 260 | $date, |
|---|
| 261 | 'Marine Day'); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | function _buildRespectfortheAgedDay() |
|---|
| 271 | { |
|---|
| 272 | $date = null; |
|---|
| 273 | if ($this->_year >= 2003) { |
|---|
| 274 | $date = $this->_calcNthMondayInMonth(9, 3); |
|---|
| 275 | } else if ($this->_year >= 1966) { |
|---|
| 276 | $date = $this->_year . '-09-15'; |
|---|
| 277 | } |
|---|
| 278 | if (!is_null($date)) { |
|---|
| 279 | $this->_addHoliday('respectfortheAgedDay', |
|---|
| 280 | $date, |
|---|
| 281 | 'Respect for the Aged Day'); |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | function _buildHealthandSportsDay() |
|---|
| 291 | { |
|---|
| 292 | $date = null; |
|---|
| 293 | if ($this->_year >= 2000) { |
|---|
| 294 | $date = $this->_calcNthMondayInMonth(10, 2); |
|---|
| 295 | } else if ($this->_year >= 1966) { |
|---|
| 296 | $date = $this->_year . '-10-10'; |
|---|
| 297 | } |
|---|
| 298 | if (!is_null($date)) { |
|---|
| 299 | $this->_addHoliday('healthandSportsDay', |
|---|
| 300 | $date, |
|---|
| 301 | 'Health and Sports Day'); |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | function _buildAutumnalEquinoxDay() |
|---|
| 311 | { |
|---|
| 312 | $day = null; |
|---|
| 313 | if ($this->_year >= 1948 && $this->_year <= 1979) { |
|---|
| 314 | $day = floor(23.2588 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 315 | } else if ($this->_year <= 2099) { |
|---|
| 316 | $day = floor(23.2488 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 317 | } else if ($this->_year <= 2150) { |
|---|
| 318 | $day = floor(24.2488 + 0.242194 * ($this->_year - 1980) - floor(($this->_year - 1980) / 4)); |
|---|
| 319 | } |
|---|
| 320 | if (!is_null($day)) { |
|---|
| 321 | $this->_addHoliday('autumnalEquinoxDay', |
|---|
| 322 | sprintf('%04d-%02d-%02d', $this->_year, 9, $day), |
|---|
| 323 | 'Autumnal Equinox Day'); |
|---|
| 324 | |
|---|
| 325 | if ($this->_year >= 2003 && |
|---|
| 326 | $this->getHolidayDate('autumnalEquinoxDay')->getDayOfWeek() == 3) { |
|---|
| 327 | $this->_addHoliday('nationalHolidayBeforeAutumnalEquinoxDay', |
|---|
| 328 | $this->getHolidayDate('autumnalEquinoxDay')->getPrevDay(), |
|---|
| 329 | 'National Holiday before Autumnal Equinox Day'); |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | function _buildNationalCultureDay() |
|---|
| 340 | { |
|---|
| 341 | if ($this->_year >= 1948) { |
|---|
| 342 | $this->_addHoliday('nationalCultureDay', |
|---|
| 343 | $this->_year . '-11-03', |
|---|
| 344 | 'National Culture Day'); |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | function _buildLaborThanksgivingDay() |
|---|
| 354 | { |
|---|
| 355 | if ($this->_year >= 1948) { |
|---|
| 356 | $this->_addHoliday('laborThanksgivingDay', |
|---|
| 357 | $this->_year . '-11-23', |
|---|
| 358 | 'Labor Thanksgiving Day'); |
|---|
| 359 | } |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | function _buildEmperorsBirthday() |
|---|
| 368 | { |
|---|
| 369 | if ($this->_year >= 1989) { |
|---|
| 370 | $this->_addHoliday('emperorsBirthday', |
|---|
| 371 | $this->_year . '-12-23', |
|---|
| 372 | 'Emperor\'s Birthday'); |
|---|
| 373 | } |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | |
|---|
| 381 | function _buildOtherMemorialDays() |
|---|
| 382 | { |
|---|
| 383 | if ($this->_year == 1959) { |
|---|
| 384 | $this->_addHoliday( |
|---|
| 385 | 'theRiteofWeddingofHIHCrownPrinceAkihito', |
|---|
| 386 | $this->_year . '-04-10', |
|---|
| 387 | 'The Rite of Wedding of HIH Crown Prince Akihito'); |
|---|
| 388 | } |
|---|
| 389 | if ($this->_year == 1989) { |
|---|
| 390 | $this->_addHoliday( |
|---|
| 391 | 'theFuneralCeremonyofEmperorShowa.', |
|---|
| 392 | $this->_year . '-02-24', |
|---|
| 393 | 'The Funeral Ceremony of Emperor Showa.'); |
|---|
| 394 | } |
|---|
| 395 | if ($this->_year == 1990) { |
|---|
| 396 | $this->_addHoliday( |
|---|
| 397 | 'theCeremonyoftheEnthronementofHisMajestytheEmperor(attheSeiden)', |
|---|
| 398 | $this->_year . '-11-12', |
|---|
| 399 | 'The Ceremony of the Enthronement of His Majesty the Emperor (at the Seiden)'); |
|---|
| 400 | } |
|---|
| 401 | if ($this->_year == 1993) { |
|---|
| 402 | $this->_addHoliday( |
|---|
| 403 | 'theRiteofWeddingofHIHCrownPrinceNaruhito', |
|---|
| 404 | $this->_year . '-06-09', |
|---|
| 405 | 'The Rite of Wedding of HIH Crown Prince Naruhito'); |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | function _buildSubstituteHolidays() |
|---|
| 415 | { |
|---|
| 416 | foreach ($this->_dates as $name => $date) { |
|---|
| 417 | if ($date->getDayOfWeek() == 0) { |
|---|
| 418 | if ($this->_year >= 2007) { |
|---|
| 419 | while (in_array($date, $this->_dates)) { |
|---|
| 420 | $date = $date->getNextDay(); |
|---|
| 421 | } |
|---|
| 422 | } else if ($date->getDate() >= '1973-04-12') { |
|---|
| 423 | $date = $date->getNextDay(); |
|---|
| 424 | if (in_array($date, $this->_dates)) { |
|---|
| 425 | continue; |
|---|
| 426 | } |
|---|
| 427 | } else { |
|---|
| 428 | continue; |
|---|
| 429 | } |
|---|
| 430 | if (!is_null($date)) { |
|---|
| 431 | $this->_addHoliday( |
|---|
| 432 | 'substituteHolidayFor' . str_replace(' ', '', $name), |
|---|
| 433 | $date, |
|---|
| 434 | 'Substitute Holiday for ' . $name); |
|---|
| 435 | } |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | function _calcNthMondayInMonth($month, $position) |
|---|
| 450 | { |
|---|
| 451 | if ($position == 1) { |
|---|
| 452 | $startday = '01'; |
|---|
| 453 | } elseif ($position == 2) { |
|---|
| 454 | $startday = '08'; |
|---|
| 455 | } elseif ($position == 3) { |
|---|
| 456 | $startday = '15'; |
|---|
| 457 | } elseif ($position == 4) { |
|---|
| 458 | $startday = '22'; |
|---|
| 459 | } elseif ($position == 5) { |
|---|
| 460 | $startday = '29'; |
|---|
| 461 | } |
|---|
| 462 | $month = sprintf("%02d", $month); |
|---|
| 463 | |
|---|
| 464 | $date = new Date($this->_year . '-' . $month . '-' . $startday); |
|---|
| 465 | while ($date->getDayOfWeek() != 1) { |
|---|
| 466 | $date = $date->getNextDay(); |
|---|
| 467 | } |
|---|
| 468 | return $date; |
|---|
| 469 | } |
|---|
| 470 | } |
|---|
| 471 | ?> |
|---|