Skip to content

Commit

Permalink
Adding Australia\Victoria region
Browse files Browse the repository at this point in the history
  • Loading branch information
brucealdridge committed Sep 20, 2016
1 parent 43dc736 commit 08382f5
Show file tree
Hide file tree
Showing 33 changed files with 1,679 additions and 0 deletions.
198 changes: 198 additions & 0 deletions src/Yasumi/Provider/Australia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<?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 Bruce Aldridge <bruce@incode.nz>
*/

namespace Yasumi\Provider;

use DateInterval;
use DateTime;
use DateTimeZone;
use Yasumi\Holiday;

/**
* Provider for all holidays in Australia.
*/
class Australia extends AbstractProvider
{
use CommonHolidays, ChristianHolidays;

/**
* Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
* country or subregion.
*/
const ID = 'AU';

public $timezone = 'Australia/Melbourne';

/**
* Initialize holidays for Australia.
*/
public function initialize()
{


// National Holidays
$this->calculateAustraliaDay();
$this->calculateNewYearHolidays();
$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->calculateChristmasDay();
}

/**
* Australia Day.
*
* Australia Day is the official National Day of Australia. Celebrated annually on 26 January,
* it marks the anniversary of the 1788 arrival of the First Fleet of British Ships at
* Port Jackson, New South Wales, and the raising of the Flag of Great Britain at Sydney Cove
* by Governor Arthur Phillip. In present-day Australia, celebrations reflect the diverse
* society and landscape of the nation, and are marked by community and family events,
* reflections on Australian history, official community awards, and citizenship ceremonies
* welcoming new immigrants into the Australian community.
*
* @link https://en.wikipedia.org/wiki/Waitangi_Day
* @link https://www.timeanddate.com/holidays/australia/australia-day
*/
public function calculateAustraliaDay()
{
$date = new DateTime("$this->year-01-26", new DateTimeZone($this->timezone));

$this->calculateHoliday('australiaDay', [], $date);
}

/**
* 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 https://www.timeanddate.com/holidays/australia/anzac-day
*/
public function calculateAnzacDay()
{
if ($this->year < 1921) {
return;
}

$date = new DateTime("$this->year-04-25", new DateTimeZone($this->timezone));

$this->calculateHoliday('anzacDay', [], $date, true, true);
}

/**
* Queens Birthday.
*
* The Queen's Birthday is an Australian public holiday but the date varies across
* states and territories. Australia celebrates this holiday because it is a constitutional
* monarchy, with the English monarch as head of state.
*
* Her actual birthday is on April 21, but it's celebrated as a public holiday on the second Monday of June.
* (Except QLD & WA)
*
* @link https://www.timeanddate.com/holidays/australia/queens-birthday
*/
public function calculateQueensBirthday()
{
$this->calculateHoliday(
'queensBirthday',
['en_AU' => 'Queens Birthday'],
'second monday of june '.$this->year,
false,
false
);
}

/**
* Christmas Day / Boxing Day.
*
* Christmas day, and Boxing day are public holidays in Australia,
* if they fall on the weekend they are moved to the next available weekday.
*
* @link https://www.timeanddate.com/holidays/australia/christmas-day-holiday
*/
public function calculateChristmasDay()
{
$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: // sunday
$christmasDay->add(new \DateInterval('P2D'));
break;
case 5: // friday
$boxingDay->add(new \DateInterval('P2D'));
break;
case 6: // saturday
$christmasDay->add(new \DateInterval('P2D'));
$boxingDay->add(new \DateInterval('P2D'));
break;
}
$this->calculateHoliday('christmasDay', [], $christmasDay);
$this->calculateHoliday('secondChristmasDay', [], $boxingDay);
}

/**
* Holidays associated with the start of the modern Gregorian calendar.
*
* New Year's Day is on January 1 and is the first day of a new year in the Gregorian calendar,
* which is used in Australia and many other countries. Due to its geographical position close
* to the International Date Line, Australia is one of the first countries in the world to
* welcome the New Year.
*
* @link https://www.timeanddate.com/holidays/australia/new-year-day
*/
public function calculateNewYearHolidays()
{
$this->calculateHoliday('newYearsDay', [], new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)));
}


/**
* @link https://www.timeanddate.com/holidays/australia/labour-day
*/
public function calculateLabourDay()
{
$date = new DateTime('first Monday in October' . " $this->year",
new DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('labourDay', [], $date, $this->locale));
}


/**
* Function to simplify moving holidays to mondays if required
* @param $shortName
* @param array $names
* @param $date
* @param bool $moveFromSaturday
* @param bool $moveFromSunday
*/
public function calculateHoliday($shortName, $names = [], $date, $moveFromSaturday = true, $moveFromSunday = true)
{
$holidayDate = $date instanceof DateTime ? $date : new DateTime($date, new DateTimeZone($this->timezone));

$day = $holidayDate->format('w');
//echo ' - '.$shortName.' - Day: '.$day."\n";
if (($day == 0 && $moveFromSunday) || ($day == 6 && $moveFromSaturday)) {
//echo ' - '.$shortName.' - Need to move: '.($day == 0 ? '1 day' : '2days')."\n";
$holidayDate->add($day == 0 ? new DateInterval('P1D') : new DateInterval('P2D'));
}

$this->addHoliday(new Holiday($shortName, $names, $holidayDate, $this->locale));
}
}
87 changes: 87 additions & 0 deletions src/Yasumi/Provider/Australia/Victoria.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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 Bruce Aldridge <bruce@incode.nz>
*/

namespace Yasumi\Provider\Australia;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;
use Yasumi\Provider\Australia;

/**
* Provider for all holidays in Victoria (Australia).
*
*/
class Victoria extends Australia
{
/**
* Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
* country or subregion.
*/
const ID = 'AU-VIC';

/**
* Initialize holidays for Victoria (Australia).
*/
public function initialize()
{
parent::initialize();

$this->calculateLabourDay();
$this->calculateQueensBirthday();
$this->calculateMelbourneCupDay();
$this->calculateAFLGrandFinalDay();
}

public function calculateChristmasDay()
{
$christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone));
$boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone));

$this->calculateHoliday('christmasDay', [], $christmasDay);
$this->calculateHoliday('secondChristmasDay', [], $boxingDay, false, true);
}

public function calculateLabourDay()
{
$date = new DateTime("second monday of march $this->year",
new DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('labourDay', [], $date, $this->locale));
}
public function calculateMelbourneCupDay()
{
$date = new DateTime('first Tuesday of November' . " $this->year",
new DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('melbourneCup', ['en_AU' => 'Melbourne Cup'], $date, $this->locale));
}

public function calculateAFLGrandFinalDay()
{
switch ($this->year) {
case 2015:
$aflGrandFinalFriday = '2015-10-02';
break;
case 2016:
$aflGrandFinalFriday = '2016-09-30';
break;
default:
return;
}

$date = new DateTime($aflGrandFinalFriday,
new DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('aflGrandFinalFriday', ['en_AU' => 'AFL Grand Final Friday'], $date, $this->locale));
}
}
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/anzacDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Translation for ANZAC Day
return [
'en_AU' => 'ANZAC Day',
'en_NZ' => 'ANZAC Day',
'en_US' => 'ANZAC Day',
];
17 changes: 17 additions & 0 deletions src/Yasumi/data/translations/australiaDay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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 Australia Day
return [
'en_AU' => 'Australia Day',
'en_US' => 'Australia Day',
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/christmasDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'da_DK' => '1. Juledag',
'de_DE' => '1. Weihnachtsfeiertag',
'el_GR' => 'Χριστούγεννα',
'en_AU' => 'Christmas Day',
'en_GB' => 'Christmas Day',
'en_NZ' => 'Christmas Day',
'en_US' => 'Christmas',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/easterMonday.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'da_DK' => '2. Påskedag',
'de_DE' => 'Ostermontag',
'el_GR' => 'Δευτέρα του Πάσχα',
'en_AU' => 'Easter Monday',
'en_GB' => 'Easter Monday',
'en_NZ' => 'Easter Monday',
'en_US' => 'Easter Monday',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/goodFriday.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'da_DK' => 'Langfredag',
'de_DE' => 'Karfreitag',
'el_GR' => 'Μεγάλη Παρασκευή',
'en_AU' => 'Good Friday',
'en_GB' => 'Good Friday',
'en_NZ' => 'Good Friday',
'en_US' => 'Good Friday',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/labourDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Translation for Labour Day
return [
'en_AU' => 'Labour Day',
'en_NZ' => 'Labour Day',
'en_US' => 'Labour Day',
'ja_JP' => '労働の日',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/newYearsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'da_DK' => 'Nytårsdag',
'de_DE' => 'Neujahr',
'el_GR' => 'Πρωτοχρονιά',
'en_AU' => 'New Year\'s Day',
'en_GB' => 'New Year\'s Day',
'en_NZ' => 'New Year\'s Day',
'en_US' => 'New Year\'s Day',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/secondChristmasDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'da_DK' => '2. Juledag',
'de_DE' => '2. Weihnachtsfeiertag',
'el_GR' => 'Σύναξις Υπεραγίας Θεοτόκου Μαρίας',
'en_AU' => 'Boxing Day',
'en_GB' => 'Boxing Day',
'en_NZ' => 'Boxing Day',
'en_US' => 'Boxing Day',
Expand Down
Loading

0 comments on commit 08382f5

Please sign in to comment.