Skip to content

Commit

Permalink
Add Australian Holidays
Browse files Browse the repository at this point in the history
These are the national holidays (for the majority of states)
  • Loading branch information
patrickomeara committed Jan 17, 2024
1 parent 9927780 commit eb6f4cc
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Countries/Australia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Australia extends Country
{
public function countryCode(): string
{
return 'au';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
'Australia Day' => '01-26',
'Anzac Day' => '04-25',
'Christmas Day' => '12-25',
'Boxing Day' => '12-26',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('Australia/Sydney');

return [
'Queen\'s Birthday' => CarbonImmutable::parse('second monday of june'),
'Good Friday' => $easter->subDays(2),
'Easter Saturday' => $easter->subDay(),
'Easter Sunday' => $easter,
'Easter Monday' => $easter->addDay(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"name": "New Year's Day",
"date": "2024-01-01"
},
{
"name": "Australia Day",
"date": "2024-01-26"
},
{
"name": "Good Friday",
"date": "2024-03-29"
},
{
"name": "Easter Saturday",
"date": "2024-03-30"
},
{
"name": "Easter Sunday",
"date": "2024-03-31"
},
{
"name": "Easter Monday",
"date": "2024-04-01"
},
{
"name": "Anzac Day",
"date": "2024-04-25"
},
{
"name": "Queen's Birthday",
"date": "2024-06-10"
},
{
"name": "Christmas Day",
"date": "2024-12-25"
},
{
"name": "Boxing Day",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/AustraliaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate australian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Australia/Melbourne');

$holidays = Holidays::for(country: 'au')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});

0 comments on commit eb6f4cc

Please sign in to comment.