Skip to content

Instantly share code, notes, and snippets.

@Phil-Venter
Last active August 29, 2025 06:02
Show Gist options
  • Select an option

  • Save Phil-Venter/2cfaef41a42ac9cbb094de5226c42929 to your computer and use it in GitHub Desktop.

Select an option

Save Phil-Venter/2cfaef41a42ac9cbb094de5226c42929 to your computer and use it in GitHub Desktop.
South African Holidays
<?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