Last active
August 29, 2025 06:02
-
-
Save Phil-Venter/2cfaef41a42ac9cbb094de5226c42929 to your computer and use it in GitHub Desktop.
South African Holidays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $year = (int) $argv[1]; | |
| $easterSunday = new DateTimeImmutable('@' . easter_date($year)); | |
| $holidayNameDateMapping = [ | |
| "Day of Goodwill" => new DateTimeImmutable("$year-12-26"), | |
| "Christmas Day" => new DateTimeImmutable("$year-12-25"), | |
| "Day of Reconciliation" => new DateTimeImmutable("$year-12-16"), | |
| "Heritage Day" => new DateTimeImmutable("$year-09-24"), | |
| "National Women's Day" => new DateTimeImmutable("$year-08-09"), | |
| "Youth Day" => new DateTimeImmutable("$year-06-16"), | |
| "Workers' Day" => new DateTimeImmutable("$year-05-01"), | |
| "Freedom Day" => new DateTimeImmutable("$year-04-27"), | |
| "Family Day" => $easterSunday->modify('next monday'), | |
| "Good Friday" => $easterSunday->modify('previous friday'), | |
| "Human Rights Day" => new DateTimeImmutable("$year-03-21"), | |
| "New Year's Day" => new DateTimeImmutable("$year-01-01"), | |
| ]; | |
| $holidays = []; | |
| foreach ($holidayNameDateMapping as $name => $holidayDate) { | |
| $dateKey = $holidayDate->format('m-d'); | |
| $holidays[$dateKey] = $name; | |
| if ((int) $holidayDate->format('N') === 7) { | |
| $observedDate = $holidayDate->modify('+1 day'); | |
| while (isset($holidays[$observedDate->format('m-d')])) { | |
| $observedDate = $observedDate->modify('+1 day'); | |
| } | |
| $observedKey = $observedDate->format('m-d'); | |
| $holidays[$observedKey] = "$name (observed)"; | |
| } | |
| } | |
| ksort($holidays); | |
| foreach ($holidays as $date => $name) { | |
| echo "$date: $name" . PHP_EOL; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment