Skip to content

Commit

Permalink
Added support for DateTimeImmutable by checking for DateTimeInterface…
Browse files Browse the repository at this point in the history
… implementations.

Signed-off-by: Sacha Telgenhof <[email protected]>
  • Loading branch information
stelgenhof committed Jan 24, 2018
1 parent fce31b3 commit 0f9bc79
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/Yasumi/Provider/Australia.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function calculateAustraliaDay()
* @param bool $moveFromSaturday
* @param bool $moveFromSunday
*
* @throws \Yasumi\Exception\InvalidDateException
* @throws \InvalidArgumentException
* @throws \Yasumi\Exception\UnknownLocaleException
* @throws \Exception
Expand All @@ -99,13 +100,12 @@ public function calculateHoliday(
$moveFromSaturday = true,
$moveFromSunday = true
) {
$holidayDate = $date instanceof DateTime ? $date : new DateTime($date, new DateTimeZone($this->timezone));
$holidayDate = $date instanceof \DateTimeInterface ? $date : new \DateTime($date,
new \DateTimeZone($this->timezone));

$day = (int)$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'));
$holidayDate = $holidayDate->add($day === 0 ? new DateInterval('P1D') : new DateInterval('P2D'));
}

$this->addHoliday(new Holiday($shortName, $names, $holidayDate, $this->locale));
Expand All @@ -127,11 +127,8 @@ public function calculateHoliday(
*/
public function calculateNewYearHolidays()
{
$this->calculateHoliday(
'newYearsDay',
[],
new DateTime("$this->year-01-01", new DateTimeZone($this->timezone))
);
$this->calculateHoliday('newYearsDay', [],
new DateTime("$this->year-01-01", new DateTimeZone($this->timezone)));
}

/**
Expand Down Expand Up @@ -209,13 +206,8 @@ public function calculateChristmasDay()
*/
public function calculateQueensBirthday()
{
$this->calculateHoliday(
'queensBirthday',
['en_AU' => 'Queens Birthday'],
'second monday of june ' . $this->year,
false,
false
);
$this->calculateHoliday('queensBirthday', ['en_AU' => 'Queens Birthday'],
'second monday of june ' . $this->year, false, false);
}

/**
Expand Down

0 comments on commit 0f9bc79

Please sign in to comment.