Skip to content

Instantly share code, notes, and snippets.

@prochor666
Last active September 21, 2017 14:55
Show Gist options
  • Select an option

  • Save prochor666/352b313bba1d22355fcd4ae99c3f2c7b to your computer and use it in GitHub Desktop.

Select an option

Save prochor666/352b313bba1d22355fcd4ae99c3f2c7b to your computer and use it in GitHub Desktop.
Holiday
<?php
class Holiday {
public $dates = [];
public function __construct(){
$this->dates = [
'1.1.',
'8.5.',
'5.7.',
'6.7.',
'28.9.',
'28.10.',
'17.11.',
'24.12.',
'25.12.',
'26.12.',
// easter is calculated automaticaly
];
}
public function workingDay($date, $workingSaturday = false) {
$today = mb_strtolower(date('D', $date));
if ( ($workingSaturday === false && ($today == 'sat' || $today == 'sun')) || ($workingSaturday === true && $today == 'sun') ) {
$nexMonday = strtotime('next Monday', $date);
$isHoliday = $this->isHoliday($nexMonday);
if ($isHoliday === false) {
return $nexMonday;
}
return $this->workingDay($nexMonday);
}
if ($this->isHoliday($date)) {
return $this->workingDay(strtotime('+1 day', $date));
}
return $date;
}
public function isHoliday($date) {
$easterStart = easter_date(date('Y', $date));
$easterFriday = strtotime('last Friday', $easterStart);
$easterMonday = strtotime('next Monday', $easterStart);
$holidays = $this->dates;
array_push($holidays, date('j.n.', $easterFriday), date('j.n.', $easterMonday));
return in_array(date('j.n.', $date), $holidays);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment