-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for New Zealand #13
Merged
stelgenhof
merged 21 commits into
azuyalabs:master
from
badams:new_zealand_holiday_provider
Apr 9, 2016
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
da46215
Adding base New Zealand holiday provider
badams 19b67cb
Adding tests for ANZAC day, fixed ANZAC start date and "Mondayisation"
badams eba6df9
Fixing start date of Queens birthdat celebration
badams 7ec4151
Adding tests for Queens Birthday
badams 42e9b0a
Adding Tests for Labour Day
badams 477929e
Adding NewZealand testsuite config
badams f06d7f6
Updating Waitangi Day calculation and adding tests
badams 535f0b9
Adding NotHoliday tests to national holidays
badams 2db27f3
Merge branch 'master' into new_zealand_holiday_provider
badams 90822be
Refactored New Year Holidays, Adding tests
badams 1817028
Refactoring xmas holiday calculations and added tests.
badams ff95546
cleaned up NewZealand::calculateNewYearHolidays()
badams c02f284
updating doc blocks
badams b84a8a5
More tests
badams e092a68
Adding translations for unique holiday names
badams b3b0f27
Merging upstream changes
badams 21a402d
Replacing hardcoded list of ANZAC dates
badams 07010c2
Refactoring HolidayDataProvider implementations in NZ test suite
badams 4c89184
Merging changes from upstream
badams 4537cb7
Merge branch 'master' into new_zealand_holiday_provider
badams 8b42aa6
Code style fixes
badams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
<?php | ||
/** | ||
* This file is part of the Yasumi package. | ||
* | ||
* Copyright (c) 2015 - 2016 AzuyaLabs | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Sacha Telgenhof <stelgenhof@gmail.com> | ||
*/ | ||
namespace Yasumi\Provider; | ||
|
||
use DateTime; | ||
use DateTimeZone; | ||
use DateInterval; | ||
use Yasumi\Holiday; | ||
|
||
/** | ||
* Provider for all holidays in New Zealand. | ||
*/ | ||
class NewZealand extends AbstractProvider | ||
{ | ||
use CommonHolidays, ChristianHolidays; | ||
|
||
/** | ||
* Initialize holidays for New Zealand. | ||
*/ | ||
public function initialize() | ||
{ | ||
$this->timezone = 'Pacific/Auckland'; | ||
|
||
// National Holidays | ||
$this->calculateNewYearHolidays(); | ||
$this->calculateWaitangiDay(); | ||
$this->calculateAnzacDay(); | ||
$this->calculateQueensBirthday(); | ||
$this->calculateLabourDay(); | ||
|
||
// Add Christian holidays | ||
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale)); | ||
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale)); | ||
$this->calculateChristmasHolidays(); | ||
} | ||
|
||
/** | ||
* Waitangi Day | ||
* | ||
* Waitangi Day (named after Waitangi, where the Treaty of Waitangi was first signed) | ||
* commemorates a significant day in the history of New Zealand. It is observed as a public holiday each | ||
* year on 6 February to celebrate the signing of the Treaty of Waitangi, New Zealand's founding document, | ||
* on that date in 1840. In recent legislation, if 6 February falls on a Saturday or Sunday, | ||
* the Monday that immediately follows becomes a public holiday. | ||
* | ||
* @link https://en.wikipedia.org/wiki/Waitangi_Day | ||
* @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp | ||
*/ | ||
public function calculateWaitangiDay() | ||
{ | ||
if ($this->year < 1974) { | ||
return; | ||
} | ||
|
||
$date = new DateTime("$this->year-02-6", new DateTimeZone($this->timezone)); | ||
|
||
if ($this->year >= 2015 && !$this->isWorkingDay($date)) { | ||
$date->modify('next monday'); | ||
} | ||
|
||
$this->addHoliday(new Holiday('waitangiDay', [], $date, $this->locale)); | ||
} | ||
|
||
/** | ||
* Christmas Day / Boxing Day | ||
* | ||
* Christmas day, and Boxing day are public holidays in New Zealand, | ||
* they are subject to mondayisation rules. | ||
* | ||
* @link http://www.timeanddate.com/holidays/new-zealand/boxing-day | ||
* @link http://www.timeanddate.com/holidays/new-zealand/christmas-day | ||
* @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp | ||
*/ | ||
public function calculateChristmasHolidays() | ||
{ | ||
$christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone)); | ||
$boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone)); | ||
|
||
switch ($christmasDay->format('w')) { | ||
case 0: | ||
$christmasDay->add(new DateInterval('P2D')); | ||
break; | ||
case 5: | ||
$boxingDay->add(new DateInterval('P2D')); | ||
break; | ||
case 6: | ||
$christmasDay->add(new DateInterval('P2D')); | ||
$boxingDay->add(new DateInterval('P2D')); | ||
break; | ||
} | ||
|
||
$this->addHoliday(new Holiday('christmasDay', [], $christmasDay, $this->locale)); | ||
$this->addHoliday(new Holiday('secondChristmasDay', [], $boxingDay, $this->locale)); | ||
} | ||
|
||
/** | ||
* Holidays associated with the start of the modern Gregorian calendar | ||
* | ||
* New Zealanders celebrate New Years Day and The Day After New Years Day, | ||
* if either of these holidays occur on a weekend, the dates need to be adjusted. | ||
* | ||
* @link https://en.wikipedia.org/wiki/Public_holidays_in_New_Zealand#Statutory_holidays | ||
* @link http://www.timeanddate.com/holidays/new-zealand/new-year-day | ||
* @link http://www.timeanddate.com/holidays/new-zealand/day-after-new-years-day | ||
* @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp | ||
*/ | ||
public function calculateNewYearHolidays() | ||
{ | ||
$newYearsDay = new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)); | ||
$dayAfterNewYearsDay = new DateTime("$this->year-01-02", new DateTimeZone($this->timezone)); | ||
|
||
switch ($newYearsDay->format('w')) { | ||
case 0: | ||
$newYearsDay->add(new DateInterval('P1D')); | ||
$dayAfterNewYearsDay->add(new DateInterval('P1D')); | ||
break; | ||
case 5: | ||
$dayAfterNewYearsDay->add(new DateInterval('P2D')); | ||
break; | ||
case 6: | ||
$newYearsDay->add(new DateInterval('P2D')); | ||
$dayAfterNewYearsDay->add(new DateInterval('P2D')); | ||
break; | ||
} | ||
|
||
$this->addHoliday(new Holiday('newYearsDay', [], $newYearsDay, $this->locale)); | ||
$this->addHoliday(new Holiday('dayAfterNewYearsDay', [], $dayAfterNewYearsDay, $this->locale)); | ||
} | ||
|
||
/** | ||
* ANZAC Day | ||
* | ||
* Anzac Day is a national day of remembrance in Australia and New Zealand that broadly commemorates all Australians | ||
* and New Zealanders "who served and died in all wars, conflicts, and peacekeeping operations" | ||
* Observed on 25 April each year. | ||
* | ||
* @link https://en.wikipedia.org/wiki/Anzac_Day | ||
* @link http://employment.govt.nz/er/holidaysandleave/publicholidays/mondayisation.asp | ||
*/ | ||
public function calculateAnzacDay() | ||
{ | ||
if ($this->year < 1921) { | ||
return; | ||
} | ||
|
||
$date = new DateTime("$this->year-04-25", new DateTimeZone($this->timezone)); | ||
|
||
if ($this->year >= 2015 && !$this->isWorkingDay($date)) { | ||
$date->modify('next monday'); | ||
} | ||
|
||
$this->addHoliday(new Holiday('anzacDay', [], $date, $this->locale)); | ||
} | ||
|
||
/** | ||
* Queens Birthday | ||
* | ||
* The official head of state of New Zealand is the Monarch of the Commonwealth Realms. | ||
* The monarch's birthday is officially celebrated in many parts of New Zealand. | ||
* On her accession in 1952 Queen Elizabeth II was proclaimed in New Zealand ‘Queen of this Realm and all her | ||
* other Realms’. Her representative in New Zealand, the governor general, has symbolic and ceremonial roles | ||
* and is not involved in the day-to-day running of the government, which is the domain of the prime minister. | ||
* | ||
* Her actual birthday is on April 21, but it's celebrated as a public holiday on the first Monday of June. | ||
* | ||
* @link http://www.timeanddate.com/holidays/new-zealand/queen-birthday | ||
*/ | ||
public function calculateQueensBirthday() | ||
{ | ||
if ($this->year < 1952) { | ||
return; | ||
} | ||
|
||
$this->addHoliday(new Holiday( | ||
'queensBirthday', | ||
[], | ||
new DateTime("first monday of june $this->year", new DateTimeZone($this->timezone)), | ||
$this->locale | ||
)); | ||
} | ||
|
||
/** | ||
* During the 19th century, workers in New Zealand tried to claim the right for an 8-hour working day. | ||
* In 1840 carpenter Samuel Parnell fought for this right in Wellington, NZ, and won. | ||
* Labour Day was first celebrated in New Zealand on October 28, 1890, when thousands of workers paraded in the | ||
* main city centres. | ||
* Government employees were given the day off to attend the parades and many businesses closed for at least part | ||
* of the day. | ||
* | ||
* The first official Labour Day public holiday in New Zealand was celebrated on the | ||
* second Wednesday in October in 1900. The holiday was moved to the fourth Monday of October in 1910 | ||
* has remained on this date since then. | ||
* | ||
* @link http://www.timeanddate.com/holidays/new-zealand/labour-day | ||
*/ | ||
public function calculateLabourDay() | ||
{ | ||
if ($this->year < 1900) { | ||
return; | ||
} | ||
|
||
$date = new DateTime( | ||
(($this->year < 1910) ? 'second wednesday of october' : 'fourth monday of october') . " $this->year", | ||
new DateTimeZone($this->timezone) | ||
); | ||
|
||
$this->addHoliday(new Holiday('labourDay', [], $date, $this->locale)); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of the Yasumi package. | ||
* | ||
* Copyright (c) 2015 - 2016 AzuyaLabs | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Sacha Telgenhof <stelgenhof@gmail.com> | ||
*/ | ||
|
||
// Translation for ANZAC Day | ||
return [ | ||
'en_US' => 'ANZAC Day', | ||
]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of the Yasumi package. | ||
* | ||
* Copyright (c) 2015 - 2016 AzuyaLabs | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Sacha Telgenhof <stelgenhof@gmail.com> | ||
*/ | ||
|
||
// Translation for Day after New Year's Day | ||
return [ | ||
'en_US' => 'Day after New Year\'s Day', | ||
]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* This file is part of the Yasumi package. | ||
* | ||
* Copyright (c) 2015 - 2016 AzuyaLabs | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Sacha Telgenhof <stelgenhof@gmail.com> | ||
*/ | ||
|
||
// Translation for Waitangi Day | ||
return [ | ||
'en_US' => 'Waitangi Day', | ||
]; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* This file is part of the Yasumi package. | ||
* | ||
* Copyright (c) 2015 - 2016 AzuyaLabs | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @author Sacha Telgenhof <stelgenhof@gmail.com> | ||
*/ | ||
|
||
namespace Yasumi\tests\NewZealand; | ||
|
||
use DateTime; | ||
use DateTimeZone; | ||
|
||
/** | ||
* Class for testing ANZAC day in the New Zealand. | ||
*/ | ||
class AnzacDayTest extends NewZealandBaseTestCase | ||
{ | ||
/** | ||
* The name of the holiday | ||
*/ | ||
const HOLIDAY = 'anzacDay'; | ||
|
||
/** | ||
* Tests ANZAC Day | ||
* | ||
* @dataProvider HolidayDataProvider | ||
* | ||
* @param int $year the year for which the holiday defined in this test needs to be tested | ||
* @param DateTime $expected the expected date | ||
*/ | ||
public function testHoliday($year, $expected) | ||
{ | ||
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, | ||
new DateTime($expected, new DateTimeZone(self::TIMEZONE))); | ||
} | ||
|
||
/** | ||
* Tests that Labour Day is not present before 1921 | ||
*/ | ||
public function testNotHoliday() | ||
{ | ||
$this->assertNotHoliday(self::REGION, self::HOLIDAY, 1920); | ||
} | ||
|
||
/** | ||
* Tests the translated name of the holiday defined in this test. | ||
*/ | ||
public function testTranslation() | ||
{ | ||
$this->assertTranslatedHolidayName( | ||
self::REGION, | ||
self::HOLIDAY, | ||
$this->generateRandomYear(1921), | ||
['en_US' => 'ANZAC Day'] | ||
); | ||
} | ||
|
||
/** | ||
* Returns a list of test dates | ||
* | ||
* @return array list of test dates for the holiday defined in this test | ||
*/ | ||
public function HolidayDataProvider() | ||
{ | ||
$data = []; | ||
|
||
for ($i = 0; $i < 100; $i++) { | ||
$year = $this->generateRandomYear(1921, 2100); | ||
$date = new DateTime("$year-04-25", new DateTimeZone(self::TIMEZONE)); | ||
|
||
// in 2015 some policy was introduced to make sure this holiday was celebrated during the working week. | ||
if ($year >= 2015 && in_array($date->format('w'), [0, 6])) { | ||
$date->modify('next monday'); | ||
} | ||
|
||
$data[] = [$year, $date->format('Y-m-d')]; | ||
} | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stelgenhof does this look okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks great! BTW There have been some new commits after your created this PR, so might want to sync up your PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll update the rest of the tests