Beispiel #1
0
 function isHoliday($date)
 {
     // insert your favorite holidays here
     $this->JDtoYMD($date, $year, $month, $day);
     if ($date == easter_days($year) + $this->MDYtoJD(3, 21, $year)) {
         $noSchool = false;
         return "Easter";
     }
     if ($date == easter_days($year) + $this->MDYtoJD(3, 21, $year) - 2) {
         $noSchool = false;
         return "Good Friday";
     }
     $jewishDate = explode("/", jdtojewish(gregoriantojd($month, $day, $year)));
     $month = $jewishDate[0];
     $day = $jewishDate[1];
     if ($month == 1 && $day == 1) {
         return "Rosh Hashanah";
     }
     if ($month == 1 && $day == 2) {
         return "Rosh Hashanah";
     }
     if ($month == 1 && $day == 10) {
         return "Yom Kippur";
     }
     if ($month == 3 && $day == 25) {
         return "Chanukkah";
     }
     if ($month == 8 && $day == 15) {
         return "Passover";
     }
     // call the base class for USA holidays
     return parent::isHoliday($date);
 }
Beispiel #2
0
 /**
  * Returns all dates calculated by easter sunday
  *
  * @param int $year
  *
  * @return \DateTime[]
  */
 protected function getEasterDates($year)
 {
     $easterSunday = new \DateTime('21.03.' . $year);
     $easterSunday->modify(sprintf('+%d days', easter_days($year)));
     $easterSunday->setTimezone(new \DateTimeZone(date_default_timezone_get()));
     $easterMonday = clone $easterSunday;
     $easterMonday->modify('+1 day');
     $maundyThursday = clone $easterSunday;
     $maundyThursday->modify('-3 days');
     $goodFriday = clone $easterSunday;
     $goodFriday->modify('-2 days');
     $saturday = clone $easterSunday;
     $saturday->modify('-1 days');
     $ascensionDay = clone $easterSunday;
     $ascensionDay->modify('+39 days');
     $pentecostSunday = clone $easterSunday;
     $pentecostSunday->modify('+49 days');
     $pentecostMonday = clone $pentecostSunday;
     $pentecostMonday->modify('+1 days');
     $pentecostSaturday = clone $pentecostSunday;
     $pentecostSaturday->modify('-1 days');
     $corpusChristi = clone $easterSunday;
     $corpusChristi->modify('+60 days');
     return array('maundyThursday' => $maundyThursday, 'easterSunday' => $easterSunday, 'easterMonday' => $easterMonday, 'saturday' => $saturday, 'goodFriday' => $goodFriday, 'ascensionDay' => $ascensionDay, 'pentecostSaturday' => $pentecostSaturday, 'pentecostSunday' => $pentecostSunday, 'pentecostMonday' => $pentecostMonday, 'corpusChristi' => $corpusChristi);
 }
 private function calculateHolidays($country, $fromYear, $toYear)
 {
     $return = [];
     if ($fromYear == $toYear) {
         $years = [$fromYear];
     } else {
         $years = [$fromYear, $toYear];
     }
     foreach ($years as $year) {
         $country_file = dirname(__DIR__) . '/data/' . $country . '.json';
         $countryHolidays = json_decode(file_get_contents($country_file), true);
         foreach ($countryHolidays as $countryHoliday) {
             if (strstr($countryHoliday['rule'], '%Y')) {
                 $rule = str_replace('%Y', $year, $countryHoliday['rule']);
             } elseif (strstr($countryHoliday['rule'], '%EASTER')) {
                 $date = new Carbon($year . '-03-21 +' . easter_days($year) . ' days');
                 $rule = str_replace('%EASTER', $date->format('Y-m-d'), $countryHoliday['rule']);
             } elseif (in_array($country, ['BR', 'US']) && strstr($countryHoliday['rule'], '%ELECTION')) {
                 $rule = $this->calculateElectionDay($country, $years, $year, $countryHoliday);
             } else {
                 $rule = $countryHoliday['rule'] . ' ' . $year;
             }
             if ($rule) {
                 $return[] = ['name' => $countryHoliday['name'], 'date' => new Carbon($rule)];
             }
         }
     }
     return $return;
 }
Beispiel #4
0
/**
 * Get easter monday.
 *
 * @param Year $year
 *
 * @return DateTimeImmutable
 */
function getEasterMonday(Year $year)
{
    $year = $year->toInt();
    $time = sprintf('%d-03-21', $year);
    $base = new DateTimeImmutable($time);
    $days = easter_days($year, CAL_EASTER_ALWAYS_GREGORIAN);
    $intervalSpec = sprintf('P%dD', $days + 1);
    $daysInterval = new DateInterval($intervalSpec);
    return $base->add($daysInterval);
}
Beispiel #5
0
 /**
  * Returns a list of test dates
  *
  * @return array list of test dates for the holiday defined in this test
  */
 public function HolidayDataProvider()
 {
     $data = [];
     for ($y = 0; $y < 50; $y++) {
         $year = $this->generateRandomYear();
         $date = new DateTime("{$year}-3-21", new DateTimeZone($this->timezone));
         $date->add(new DateInterval('P' . (easter_days($year) + 1) . 'D'));
         $data[] = [$year, $date->format('Y-m-d')];
     }
     return $data;
 }
Beispiel #6
0
function is_market_closed($date)
{
    $year = $date->format('Y');
    // federal holidays
    $federal_holidays = [adjust_fixed_holiday($year . '-01-01'), date('Y-m-d', strtotime("third Monday of January {$year}")), date('Y-m-d', strtotime("third Monday of February {$year}")), date("Y-m-d", strtotime("+" . (easter_days($year) - 2) . " days", strtotime("{$year}-03-21 12:00:00"))), date('Y-m-d', strtotime("last Monday of May {$year}")), adjust_fixed_holiday($year . '-07-04', 'last friday'), date('Y-m-d', strtotime("first Monday of September {$year}")), date('Y-m-d', strtotime("last Thursday of November {$year}")), adjust_fixed_holiday($year . '-12-25')];
    if (in_array($date->format('Y-m-d'), $federal_holidays)) {
        $date->modify('next day');
    }
    // saturday or sunday
    if (is_weekend($date)) {
        $date->modify('next monday');
    }
    return $date->format('Y-m-d');
}
Beispiel #7
0
 /**
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     $testDate = ToDate::normalizeDate($date, $this->offset . ' days');
     list($weekDay, $dayCheck, $year) = explode('-', $testDate->format('N-nd-Y'));
     // easter is never after 25.04, never before 22.03 and always on a sunday
     if ($dayCheck > 425 || $weekDay != 7 || $dayCheck < 322) {
         return false;
     }
     if (!isset(self::$easterCache[$year])) {
         $easterDate = new \DateTime('21-03-' . $year);
         $easterDate->modify(easter_days($year) . ' days');
         self::$easterCache[$year] = $easterDate;
     } else {
         $easterDate = self::$easterCache[$year];
     }
     return $testDate == $easterDate;
 }
Beispiel #8
0
 /**
  * Checks if the given date is a working day.
  *
  * @param \Jyxo\Time\Time $day Date to be checked
  * @return boolean
  */
 public static function isWorkDay(\Jyxo\Time\Time $day)
 {
     $holidays = self::$holidays;
     // Adds Easter Monday. easter_date is supposed to be buggy http://cz.php.net/manual/en/function.easter-date.php#80664
     $year = (int) $day->format('Y');
     $days = easter_days($year);
     // $days returns the number of days from March 21st until the Easter Sunday, +1 because of Monday
     $holidays[] = date('j.n', strtotime($year . '-03-21 +' . ($days + 1) . ' days'));
     $isWorkDay = true;
     if ($day->format('N') > 5) {
         // Saturday or Sunday
         $isWorkDay = false;
     } elseif (in_array($day->format('j.n'), $holidays)) {
         // Public holiday, hurray!
         $isWorkDay = false;
     }
     return $isWorkDay;
 }
Beispiel #9
0
 /**
  * Returns the easter date for the current year
  *
  * @return \PSX\DateTime
  */
 public function getEasterDate()
 {
     $easter = new \DateTime($this->getYear() . '-03-21');
     $days = easter_days($this->getYear());
     return $easter->add(new DateInterval('P' . $days . 'D'));
 }
Beispiel #10
0
 /**
  * Calculate the date $interval working days from a date, not including bank holidays or weekends.
  *
  * Recursive function with comprehensive United Kingdom bank holiday checker.
  * Do not use stupidly large intervals!
  *
  * @param integer $day			- day of start date
  * @param integer $month		- month of start date
  * @param integer $year			- year of start date
  * @param integer $interval		- number of days
  *
  * @return string			- calculated date
  * @access public
  */
 public function working_days_from($day, $month, $year, $interval)
 {
     // get date + 1 day
     $date = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24);
     // array for bank holidays
     $bankhols = array();
     // New year's day
     switch (date("w", strtotime("{$year}-01-01 12:00:00"))) {
         case 6:
             $bankhols[] = "{$year}-01-03";
             break;
         case 0:
             $bankhols[] = "{$year}-01-02";
             break;
         default:
             $bankhols[] = "{$year}-01-01";
             break;
     }
     // Good Friday
     $bankhols[] = date("Y-m-d", strtotime("+" . (easter_days($year) - 2) . " days", strtotime("{$year}-03-21 12:00:00")));
     // Easter Monday
     $bankhols[] = date("Y-m-d", strtotime("+" . (easter_days($year) + 1) . " days", strtotime("{$year}-03-21 12:00:00")));
     // May Day
     if ($year == 1995) {
         // VE day 50th anniversary year exception
         $bankhols[] = "1995-05-08";
     } else {
         switch (date("w", strtotime("{$year}-05-01 12:00:00"))) {
             case 0:
                 $bankhols[] = "{$year}-05-02";
                 break;
             case 1:
                 $bankhols[] = "{$year}-05-01";
                 break;
             case 2:
                 $bankhols[] = "{$year}-05-07";
                 break;
             case 3:
                 $bankhols[] = "{$year}-05-06";
                 break;
             case 4:
                 $bankhols[] = "{$year}-05-05";
                 break;
             case 5:
                 $bankhols[] = "{$year}-05-04";
                 break;
             case 6:
                 $bankhols[] = "{$year}-05-03";
                 break;
         }
     }
     // Whitsun
     if ($year == 2002) {
         // exception year
         $bankhols[] = "2002-06-03";
         $bankhols[] = "2002-06-04";
     } else {
         switch (date("w", strtotime("{$year}-05-31 12:00:00"))) {
             case 0:
                 $bankhols[] = "{$year}-05-25";
                 break;
             case 1:
                 $bankhols[] = "{$year}-05-31";
                 break;
             case 2:
                 $bankhols[] = "{$year}-05-30";
                 break;
             case 3:
                 $bankhols[] = "{$year}-05-29";
                 break;
             case 4:
                 $bankhols[] = "{$year}-05-28";
                 break;
             case 5:
                 $bankhols[] = "{$year}-05-27";
                 break;
             case 6:
                 $bankhols[] = "{$year}-05-26";
                 break;
         }
     }
     // Summer Bank Holiday:
     switch (date("w", strtotime("{$year}-08-31 12:00:00"))) {
         case 0:
             $bankhols[] = "{$year}-08-25";
             break;
         case 1:
             $bankhols[] = "{$year}-08-31";
             break;
         case 2:
             $bankhols[] = "{$year}-08-30";
             break;
         case 3:
             $bankhols[] = "{$year}-08-29";
             break;
         case 4:
             $bankhols[] = "{$year}-08-28";
             break;
         case 5:
             $bankhols[] = "{$year}-08-27";
             break;
         case 6:
             $bankhols[] = "{$year}-08-26";
             break;
     }
     // Christmas
     switch (date("w", strtotime("{$year}-12-25 12:00:00"))) {
         case 5:
             $bankhols[] = "{$year}-12-25";
             $bankhols[] = "{$year}-12-28";
             break;
         case 6:
             $bankhols[] = "{$year}-12-27";
             $bankhols[] = "{$year}-12-28";
             break;
         case 0:
             $bankhols[] = "{$year}-12-26";
             $bankhols[] = "{$year}-12-27";
             break;
         default:
             $bankhols[] = "{$year}-12-25";
             $bankhols[] = "{$year}-12-26";
     }
     // Millenium eve
     if ($year == 1999) {
         $bankhols[] = "1999-12-31";
     }
     // William and Kate royal wedding
     if ($year == 2011) {
         $bankhols[] = "2011-04-29";
     }
     // Queen golden jubilee
     if ($year == 2002) {
         $bankhols[] = "2002-06-03";
     }
     // Queen diamond jubilee
     if ($year == 2012) {
         $bankhols[] = "2012-06-05";
     }
     if (date("l", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24) == "Saturday" || date("l", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24) == "Sunday") {
         // day is weekend, do not count as working day
         null;
     } elseif (in_array($date, $bankhols)) {
         // day is bank holiday, do not count
         null;
     } else {
         // this is a working day and counts towards the goal date
         $interval = $interval - 1;
     }
     if ($interval == 0) {
         // goal reached, return this date
         return $date;
     } else {
         // try the next date
         $nday = date("d", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24);
         $nmonth = date("m", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24);
         $nyear = date("Y", mktime(0, 0, 0, $month, $day, $year) + 60 * 60 * 24);
         $date = $this->working_days_from($nday, $nmonth, $nyear, $interval);
     }
     // return calculated date
     return $date;
 }
Beispiel #11
0
 /**
  * Checks if $date is a SEPA TARGET day. Every day is a TARGET day except for saturdays, sundays
  * new year's day, good friday, easter monday, the may holiday, first and second christmas holiday.
  * @param \DateTime $date
  * @return bool
  */
 private static function dateIsTargetDay(\DateTime $date)
 {
     // $date is a saturday or sunday
     if ($date->format('N') === '6' || $date->format('N') === '7') {
         return false;
     }
     $day = $date->format('m-d');
     if ($day === '01-01' || $day === '05-01' || $day === '12-25' || $day === '12-26') {
         // second christmas day
         return false;
     }
     $year = $date->format('Y');
     $daysToEasterSunday = easter_days((int) $year);
     $goodFriday = \DateTime::createFromFormat('Y-m-d', $year . '-03-21')->modify('+' . ($daysToEasterSunday - 2) . ' days')->format('m-d');
     $easterMonday = \DateTime::createFromFormat('Y-m-d', $year . '-03-21')->modify('+' . ($daysToEasterSunday + 1) . ' days')->format('m-d');
     if ($day === $goodFriday || $day === $easterMonday) {
         return false;
     }
     return true;
 }
Beispiel #12
0
 /**
  *
  * @param int $year
  * @return type
  */
 private function getEasterDatetime($year)
 {
     $base = new \DateTime("{$year}-03-21");
     $days = easter_days($year);
     return $base->add(new \DateInterval("P{$days}D"));
 }
 /**
  * Returns array of easter dates as DateTime objects for the year
  * specified as a DateTime object
  *
  * @param \DateTime $date Any date in the year to get easter dates
  *
  * @access public
  * @static
  * @return array<\DateTime>
  */
 public static function getEasterForDateTime(\DateTime $date)
 {
     $date->modify('21 march')->modify('+' . easter_days($date->format('Y')) . ' days');
     $goodFriday = clone $date;
     $easterMonday = clone $date;
     return array('goodFriday' => $goodFriday->modify('previous friday'), 'easterSunday' => $date, 'easterMonday' => $easterMonday->modify('next monday'));
 }
Beispiel #14
0
 /**
  * Generate table with german holidays
  * @access public
  * @return boolean
  */
 public function sCreateHolidaysTable()
 {
     if (!function_exists('easter_days')) {
         function easter_days($year)
         {
             $G = $year % 19;
             $C = (int) ($year / 100);
             $H = (int) ($C - (int) ($C / 4) - (int) ((8 * $C + 13) / 25) + 19 * $G + 15) % 30;
             $I = (int) $H - (int) ($H / 28) * (1 - (int) ($H / 28) * (int) (29 / ($H + 1)) * ((int) (21 - $G) / 11));
             $J = ($year + (int) ($year / 4) + $I + 2 - $C + (int) ($C / 4)) % 7;
             $L = $I - $J;
             $m = 3 + (int) (($L + 40) / 44);
             $d = $L + 28 - 31 * (int) ($m / 4);
             $E = mktime(0, 0, 0, $m, $d, $year) - mktime(0, 0, 0, 3, 21, $year);
             return intval(round($E / (60 * 60 * 24), 0));
         }
     }
     $sql = "\n\t\t\tSELECT id, calculation, `date`\n\t\t\tFROM `s_premium_holidays`\n\t\t\tWHERE `date`<CURDATE()\n\t\t";
     $holidays = $this->sSYSTEM->sDB_CONNECTION->CacheGetAssoc(60, $sql);
     if (empty($holidays)) {
         return true;
     }
     foreach ($holidays as $id => $holiday) {
         $calculation = $holiday['calculation'];
         $datestamp = strtotime($holiday['date']);
         $date = date('Y-m-d', $datestamp);
         $year = date('Y', $datestamp) + 1;
         $easter_date = date('Y-m-d', mktime(0, 0, 0, 3, 21 + easter_days($year), $year));
         $calculation = preg_replace("#DATE\\('(\\d+)[\\-/](\\d+)'\\)#i", "DATE(CONCAT(YEAR(),'-','\$1-\$2'))", $calculation);
         $calculation = str_replace("EASTERDATE()", "'{$easter_date}'", $calculation);
         $calculation = str_replace("YEAR()", "'{$year}'", $calculation);
         $calculation = str_replace("DATE()", "'{$date}'", $calculation);
         $sql = "UPDATE s_premium_holidays SET `date`= {$calculation} WHERE id = {$id}";
         $this->sSYSTEM->sDB_CONNECTION->Execute($sql);
     }
 }
 /**
  * Generates swedish days off (workfree days)
  *
  * Calculations verified 2012.06.06
  *
  * Details (in swedish) here:
  * http://sv.wikipedia.org/wiki/Helgdag#Allm.C3.A4nna_helgdagar_i_Sverige
  */
 function daysOffSwe($year)
 {
     if (!is_numeric($year)) {
         return false;
     }
     $res = array();
     //Nyårsdagen: 1:a januari
     $ts = mktime(0, 0, 0, 1, 1, $year);
     $res[] = array($ts, 'Nyårsdagen');
     //Trettondag jul: 6:e januari
     $ts = mktime(0, 0, 0, 1, 6, $year);
     $res[] = array($ts, 'Trettondag jul');
     //Första maj: 1:a maj
     $ts = mktime(0, 0, 0, 5, 1, $year);
     $res[] = array($ts, 'Första maj');
     //Sveriges nationaldag: 6:e juni
     $ts = mktime(0, 0, 0, 6, 6, $year);
     $res[] = array($ts, 'Sveriges nationaldag');
     //Julafton: 24:e december
     $ts = mktime(0, 0, 0, 12, 24, $year);
     $res[] = array($ts, 'Julafton');
     //Juldagen: 25:e december
     $ts = mktime(0, 0, 0, 12, 25, $year);
     $res[] = array($ts, 'Juldagen');
     //Annandag jul: 26:e december
     $ts = mktime(0, 0, 0, 12, 26, $year);
     $res[] = array($ts, 'Annandag jul');
     //Nyårsafton: 31 december
     $ts = mktime(0, 0, 0, 12, 31, $year);
     $res[] = array($ts, 'Nyårsafton');
     $easter_ofs = easter_days($year, CAL_GREGORIAN);
     //number of days after March 21 on which Easter falls
     //Skärtorsdagen (rörlig): torsdagen närmast före påskdagen
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs - 3, $year);
     $res[] = array($ts, 'Skärtorsdagen');
     //Långfredagen (rörlig): fredagen närmast före påskdagen
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs - 2, $year);
     $res[] = array($ts, 'Långfredagen');
     //Påskafton (rörlig): dagen innan påskdagen
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs - 1, $year);
     $res[] = array($ts, 'Påskafton');
     //Påskdagen (rörlig): söndagen närmast efter den fullmåne som infaller på eller närmast efter den 21 mars
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs, $year);
     $res[] = array($ts, 'Påskdagen');
     //Annandag påsk (rörlig): dagen efter påskdagen. alltid måndag
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs + 1, $year);
     $res[] = array($ts, 'Annandag påsk');
     //Kristi himmelfärdsdag (rörlig): sjätte torsdagen efter påskdagen (39 dagar efter)
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs + 39, $year);
     $res[] = array($ts, 'Kristi himmelfärdsdag');
     //Pingsdagen (rörlig): sjunde söndagen efter påskdagen (49 dagar efter)
     $ts = mktime(0, 0, 0, 3, 21 + $easter_ofs + 49, $year);
     $res[] = array($ts, 'Pingstdagen');
     //Midsommardagen (rörlig): den lördag som infaller under tiden den 20-26 jun
     $ts = mktime(0, 0, 0, 6, 20, $year);
     //20:e juni
     $dow = date('N', $ts);
     //day of week. 1=monday,7=sunday
     $ts = mktime(0, 0, 0, 6, 20 - $dow + 6, $year);
     $res[] = array($ts, 'Midsommardagen');
     //Midsommarafton (rörlig): dagen innan midsommardagen
     $ts = mktime(0, 0, 0, 6, 20 - $dow + 5, $year);
     $res[] = array($ts, 'Midsommarafton');
     //Alla helgons dag (rörlig): den lördag som infaller under tiden den 31 oktober-6 november
     for ($i = 31; $i <= 37; $i++) {
         $ts = mktime(0, 0, 0, 10, $i, $year);
         $dow = date('N', $ts);
         //day of week. 1=monday,7=sunday
         if ($dow == 6) {
             break;
         }
     }
     $res[] = array($ts, 'Alla helgons dag');
     $out = array();
     foreach ($res as $r) {
         $e = new CalendarEvent();
         $e->setDate($r[0]);
         $e->title = $r[1];
         $out[] = $e;
     }
     return $out;
 }
Beispiel #16
0
 /**
  * Retourne les périodes déduites à partir des règles applicables au jour passé en paramètre 
  * @param \DateTime $dtDay
  * @param array $rule
  * @return type
  * @throws Exception
  */
 private function getActiveDefinedPeriods(\DateTime $dtDay, array $rule)
 {
     if (!isset($rule['p']) && !isset($rule['periods'])) {
         // pas de périodes de définies = résultat vide
         return [];
     }
     $dayValid = true;
     $aPeriods = [];
     foreach ($rule as $name => $values) {
         switch ($name) {
             case "periods":
             case "p":
                 foreach ($values as $value) {
                     if (is_array($value) && isset($value['min']) && isset($value['max']) && (int) $value['min'] < (int) $value['max']) {
                         $aPeriods[] = ["begin" => (int) $value['min'], "end" => (int) $value['max']];
                     } else {
                         throw new Exception("({$name}) Invalid rule parameter.");
                     }
                 }
                 break;
             case "days":
             case "d":
                 $sDate = $dtDay->format("Ymd");
                 $dayValid = false;
                 foreach ($values as $value) {
                     if (is_array($value) && isset($value['min']) && isset($value['max']) && $sDate >= $value['min'] && $sDate <= $value['max']) {
                         $dayValid = true;
                         break;
                     } elseif (is_string($value) && $value === $sDate) {
                         $dayValid = true;
                         break;
                     }
                 }
                 if (!$dayValid) {
                     return [];
                 }
                 break;
             case "weekdays":
             case "wd":
                 $wd = (int) $dtDay->format("w") % 7;
                 $dayValid = false;
                 foreach ($values as $value) {
                     if (is_array($value) && isset($value['min']) && isset($value['max']) && $wd >= (int) $value['min'] && $wd <= (int) $value['max']) {
                         $dayValid = true;
                         break;
                     } elseif (is_string($value) && $wd === (int) $value) {
                         $dayValid = true;
                         break;
                     }
                 }
                 if (!$dayValid) {
                     return [];
                 }
                 break;
             case "birddays":
             case "bd":
                 $bd = $dtDay->format("md");
                 $dayValid = false;
                 foreach ($values as $value) {
                     if (is_array($value) && isset($value['min']) && isset($value['max']) && $bd >= $value['min'] && $bd <= $value['max']) {
                         $dayValid = true;
                         break;
                     } elseif (is_string($value) && $bd === $value) {
                         $dayValid = true;
                         break;
                     }
                 }
                 if (!$dayValid) {
                     return [];
                 }
                 break;
             case "yeardays":
             case "yd":
                 $yd = (int) $dtDay->format("z") + 1;
                 $dayValid = false;
                 foreach ($values as $value) {
                     if (is_array($value) && isset($value['min']) && isset($value['max']) && $yd >= (int) $value['min'] && $yd <= (int) $value['max']) {
                         $dayValid = true;
                         break;
                     } elseif (is_string($value) && $yd === (int) $value) {
                         $dayValid = true;
                         break;
                     }
                 }
                 if (!$dayValid) {
                     return [];
                 }
                 break;
             case "specialdays":
             case "sd":
                 $year = $dtDay->format("Y");
                 $ecart = easter_days($year);
                 $dtEaster = (new DateTime("{$year}-03-21"))->modify("+ {$ecart} d");
                 $dtEasterMonday = clone $dtEaster;
                 $dtEasterMonday->modify("+1d");
                 $dtAscension = clone $dtEaster;
                 $dtAscension->modify("+39d");
                 $dtPentecost = clone $dtEaster;
                 $dtPentecost->modify("+88d");
                 $dtPentecostMonday = clone $dtEaster;
                 $dtPentecostMonday->modify("+89d");
                 $dayValid = false;
                 foreach ($values as $value) {
                     if (is_string($value)) {
                         if (($value === "easter" || $value === "paques" || $value === "pâques") && $dtDay->format("ymd") == $dtEaster->format("ymd")) {
                             $dayValid = true;
                             break;
                         } elseif (($value === "easterMonday" || $value === "lundiPaques" || $value === "lundiPâques") && $dtDay->format("ymd") == $dtEasterMonday->format("ymd")) {
                             $dayValid = true;
                             break;
                         } elseif ($value === "ascension" && $dtDay->format("ymd") == $dtAscension->format("ymd")) {
                             $dayValid = true;
                             break;
                         } elseif (($value === "pentecost" || $value === "pentecote" || $value === "pentecôte") && $dtDay->format("ymd") == $dtPentecost->format("ymd")) {
                             $dayValid = true;
                             break;
                         } elseif (($value === "pentecostMonday" || $value === "lundiPentecote" || $value === "lundiPentecôte") && $dtDay->format("ymd") == $dtPentecostMonday->format("ymd")) {
                             $dayValid = true;
                             break;
                         }
                     } else {
                         throw new Exception("({$name}) Invalid rule parameter.");
                     }
                 }
                 if (!$dayValid) {
                     return [];
                 }
                 break;
             default:
                 throw new Exception("({$name}) Invalid rule parameter.");
         }
     }
     if ($dayValid) {
         return $aPeriods;
     } else {
         return [];
     }
 }
 /**
  * Wrapper for easter_days function
  *
  * @param  int $year
  * @return int
  */
 private function getEasterDays($year)
 {
     if (!function_exists('easter_days')) {
         return $this->easterDaysFallback($year);
     }
     return easter_days($year);
 }
Beispiel #18
0
// 31
echo "There was {$num} days in August 2003";
echo "<br/>";
echo "<pre>";
//cal_from_jd ( int $jd , int $calendar )
$today = unixtojd(mktime(0, 0, 0, 8, 16, 2003));
print_r(cal_from_jd($today, CAL_GREGORIAN));
echo "<br/>";
echo "<pre>";
$info = cal_info(0);
print_r($info);
//指定年份的复活节 午夜时分的时间戳
echo "<br/>";
echo date("M-d-Y", easter_date(1999));
echo "<br/>";
echo easter_days(2016);
echo "<br/>";
$date = new DateTime('2000-01-01');
$date->add(new DateInterval('P10D'));
echo $date->format('Y-m-d') . "\n";
//2000-01-11
echo "<br/>";
$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');
echo "<br/>";
$date = new DateTime('2016-12-12');
$date->modify('+1 day');
echo $date->format('Y-m-d');
echo "<br/>";
$date = new DateTime();
$date->setDate(2001, 2, 3);
Beispiel #19
0
[expect php]
[file]
<?php 
echo frenchtojd(-1, -1, -1), "\n";
echo frenchtojd(0, 0, 0), "\n";
echo frenchtojd(1, 1, 1), "\n";
echo frenchtojd(14, 31, 15), "\n";
echo easter_days(1999), "\n";
echo easter_days(1492), "\n";
echo easter_days(1913), "\n";
$num = cal_days_in_month(CAL_GREGORIAN, 8, 2003);
echo "There are {$num} days in August 2003\n";
$num = cal_days_in_month(CAL_GREGORIAN, 2, 2003);
echo "There are {$num} days in February 2003\n";
$num = cal_days_in_month(CAL_GREGORIAN, 2, 2004);
echo "There are {$num} days in February 2004\n";
$num = cal_days_in_month(CAL_GREGORIAN, 12, 2034);
echo "There are {$num} days in December 2034\n";
echo cal_to_jd(CAL_GREGORIAN, 8, 26, 74), "\n";
echo cal_to_jd(CAL_JULIAN, 8, 26, 74), "\n";
echo cal_to_jd(CAL_JEWISH, 8, 26, 74), "\n";
echo cal_to_jd(CAL_FRENCH, 8, 26, 74), "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002))), "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002), true)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002), true, CAL_JEWISH_ADD_ALAFIM_GERESH)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002), true, CAL_JEWISH_ADD_ALAFIM)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002), true, CAL_JEWISH_ADD_ALAFIM_GERESH + CAL_JEWISH_ADD_ALAFIM)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 28, 2002), true, CAL_JEWISH_ADD_GERESHAYIM)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 8, 2002), true, CAL_JEWISH_ADD_GERESHAYIM)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 8, 2002), true, CAL_JEWISH_ADD_GERESHAYIM + CAL_JEWISH_ADD_ALAFIM_GERESH)) . "\n";
echo bin2hex(jdtojewish(gregoriantojd(10, 8, 2002), true, CAL_JEWISH_ADD_GERESHAYIM + CAL_JEWISH_ADD_ALAFIM)) . "\n";
 /**
  *
  * @param int $year
  * @return DateTime
  */
 protected function getEasterSunday($year)
 {
     return new DateTime($year . '-03-21 + ' . easter_days($year) . ' DAYS');
 }
Beispiel #21
0
 private static function easter($year)
 {
     $days = easter_days($year);
     $easter = \DateTime::createFromFormat('Y-m-d', $year . '-3-21');
     $easter->setTime(0, 0, 0);
     $easter->add(new \DateInterval('P' . $days . 'D'));
     $easter->setTime(0, 0, 0);
     return $easter;
 }
 /**
 easter_date() relies on your system's C library time functions, rather than using PHP's internal date and time functions. As a consequence, easter_date() uses the TZ environment variable to determine the time zone it should operate in, rather than using PHP's default time zone, which may result in unexpected behaviour when using this function in conjunction with other date functions in PHP.
 As a workaround, you can use the easter_days() with DateTime and DateInterval to calculate the start of Easter in your PHP time zone as follows:
 **/
 function get_easter_datetime($year = null)
 {
     $base = new DateTime("{$year}-03-21");
     $days = easter_days($year);
     return $base->add(new DateInterval("P{$days}D"));
 }
 /**
  * Provides a DateTime object that represents easter sunday for this year.<br/>
  * The time is always set to 00:00:00.
  *
  * @param int $year The year for which to calculcate the easter sunday date
  *
  * @throws InvalidArgumentException
  *
  * @return DateTime
  */
 protected function getEaster($year)
 {
     $easter = new DateTime('now', $this->getTimeZone());
     $easter->setDate($year, 3, 21);
     $easter->setTime(0, 0, 0);
     $easter->modify('+' . easter_days($year) . 'days');
     return $easter;
 }
Beispiel #24
0
 /**
  * get the day of the year of easter sunday for a given year
  * 
  * starts with 0, so 0 is the 1st of January
  * 
  * @param integer $year
  * @return integer
  */
 protected function getDayOfYearForEasterSunday($year = null)
 {
     /**
      * the day of the year of the equinox in March
      * 
      * You don't know what it is? Well, its basically the 21st of March. :)
      * 
      * @var integer
      * @see http://en.wikipedia.org/wiki/Equinox
      */
     $equinox = intval(date('z', mktime(0, 0, 0, 3, 21, $year)));
     return $equinox + easter_days($year);
 }
 function getNextDate($epoch = FALSE)
 {
     if ($epoch == '') {
         $epoch = TTDate::getTime();
     }
     if ($this->getSpecialDay() == 1 or $this->getSpecialDay() == 5) {
         Debug::text('Easter Sunday Date...', __FILE__, __LINE__, __METHOD__, 10);
         //Use easter_days() instead, as easter_date returns incorrect values for some timezones/years (2010 and US/Eastern on Windows)
         //$easter_epoch = easter_date(date('Y', $epoch));
         $easter_epoch = mktime(12, 0, 0, 3, 21 + easter_days(date('Y', $epoch)), date('Y', $epoch));
         //Fix "cross-year" bug.
         if ($easter_epoch < $epoch) {
             //$easter_epoch = easter_date(date('Y', $epoch)+1);
             $easter_epoch = mktime(12, 0, 0, 3, 21 + easter_days(date('Y', $epoch) + 1), date('Y', $epoch) + 1);
         }
         if ($this->getSpecialDay() == 1) {
             Debug::text('Good Friday Date...', __FILE__, __LINE__, __METHOD__, 10);
             //$holiday_epoch = mktime(12,0,0,date('n',$easter_epoch),date('j',$easter_epoch) - 2, date('Y', $easter_epoch));
             $holiday_epoch = $easter_epoch - 2 * 86400;
         } else {
             $holiday_epoch = $easter_epoch;
         }
     } else {
         if ($this->getType() == 10) {
             //Static
             Debug::text('Static Date...', __FILE__, __LINE__, __METHOD__, 10);
             //Static date
             $holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch));
             if ($holiday_epoch < $epoch) {
                 $holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch) + 1);
             }
         } elseif ($this->getType() == 20) {
             //Dynamic - Week Interval
             Debug::text('Dynamic - Week Interval... Current Month: ' . TTDate::getMonth($epoch) . ' Holiday Month: ' . $this->getMonth(), __FILE__, __LINE__, __METHOD__, 10);
             //Dynamic
             $start_month_epoch = TTDate::getBeginMonthEpoch($epoch);
             $end_month_epoch = mktime(12, 0, 0, $this->getMonth() + 1, 1, date('Y', $epoch) + 1);
             Debug::text('Start Epoch: ' . TTDate::getDate('DATE+TIME', $start_month_epoch) . ' End Epoch: ' . TTDate::getDate('DATE+TIME', $end_month_epoch), __FILE__, __LINE__, __METHOD__, 10);
             //Get all day of weeks in the month. Determine which is less or greater then day.
             $day_of_week_dates = array();
             $week_interval = 0;
             for ($i = $start_month_epoch; $i <= $end_month_epoch; $i += 86400) {
                 if (TTDate::getMonth($i) == $this->getMonth()) {
                     $day_of_week = TTDate::getDayOfWeek($i);
                     //Debug::text('I: '. $i .'('.TTDate::getDate('DATE+TIME', $i).') Current Day Of Week: '. $day_of_week .' Looking for Day Of Week: '. $this->getDayOfWeek(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($day_of_week == abs($this->getDayOfWeek())) {
                         $day_of_week_dates[] = date('j', $i);
                         Debug::text('I: ' . $i . ' Day Of Month: ' . date('j', $i), __FILE__, __LINE__, __METHOD__, 10);
                         $week_interval++;
                     }
                     if ($week_interval >= $this->getWeekInterval()) {
                         $tmp_holiday_epoch = mktime(12, 0, 0, $this->getMonth(), $day_of_week_dates[$this->getWeekInterval() - 1], date('Y', $i));
                         //Make sure we keep processing until the holiday comes AFTER todays date.
                         if ($tmp_holiday_epoch > $epoch) {
                             break;
                         }
                     }
                 }
             }
             //Debug::Arr($day_of_week_dates, 'Week Dates Arr: ', __FILE__, __LINE__, __METHOD__, 10);
             //$holiday_epoch = mktime(12,0,0, $this->getMonth(), $day_of_week_dates[$this->getWeekInterval()-1], date('Y', $i));
             $holiday_epoch = $tmp_holiday_epoch;
         } elseif ($this->getType() == 30) {
             //Dynamic - Pivot Day
             Debug::text('Dynamic - Pivot Date...', __FILE__, __LINE__, __METHOD__, 10);
             //Dynamic
             if (TTDate::getMonth($epoch) > $this->getMonth()) {
                 $year_modifier = 1;
             } else {
                 $year_modifier = 0;
             }
             $start_epoch = mktime(12, 0, 0, $this->getMonth(), $this->getDayOfMonth(), date('Y', $epoch) + $year_modifier);
             $holiday_epoch = $start_epoch;
             $x = 0;
             $x_max = 100;
             if ($this->getPivotDayDirection() == 10 or $this->getPivotDayDirection() == 30) {
                 $direction_multiplier = -1;
             } else {
                 $direction_multiplier = 1;
             }
             $adjustment = 86400 * $direction_multiplier;
             // Adjust by 1 day before or after.
             if ($this->getPivotDayDirection() == 10 or $this->getPivotDayDirection() == 20) {
                 $holiday_epoch += $adjustment;
             }
             while ($this->getDayOfWeek() != TTDate::getDayOfWeek($holiday_epoch) and $x < $x_max) {
                 Debug::text('X: ' . $x . ' aTrying...' . TTDate::getDate('DATE+TIME', $holiday_epoch), __FILE__, __LINE__, __METHOD__, 10);
                 $holiday_epoch += $adjustment;
                 $x++;
             }
         }
     }
     Debug::text('Next Date for: ' . $this->getName() . ' is: ' . TTDate::getDate('DATE+TIME', $holiday_epoch), __FILE__, __LINE__, __METHOD__, 10);
     return $holiday_epoch;
 }
 private function calculateHolidays($country, $year, $range = false)
 {
     $return = [];
     if ($range) {
         $years = [$year - 1, $year, $year + 1];
     } else {
         $years = [$year];
     }
     foreach ($years as $year) {
         if ($this->cache) {
             $cache_key = 'holidayapi:' . $country . ':holidays:' . $year;
             $country_holidays = $this->cache->get($cache_key);
         } else {
             $country_holidays = false;
         }
         if ($country_holidays) {
             $country_holidays = unserialize($country_holidays);
         } else {
             $country_file = '../data/' . $country . '.json';
             if (!file_exists($country_file)) {
                 throw new \Exception('The supplied country (' . $country . ') is not supported at this time.');
             }
             $country_holidays = json_decode(file_get_contents($country_file), true);
             $calculated_holidays = [];
             foreach ($country_holidays as $country_holiday) {
                 if (strstr($country_holiday['rule'], '%Y')) {
                     $rule = str_replace('%Y', $year, $country_holiday['rule']);
                 } elseif (strstr($country_holiday['rule'], '%EASTER')) {
                     $rule = str_replace('%EASTER', date('Y-m-d', strtotime($year . '-03-21 +' . easter_days($year) . ' days')), $country_holiday['rule']);
                 } elseif (in_array($country, ['BR', 'US']) && strstr($country_holiday['rule'], '%ELECTION')) {
                     switch ($country) {
                         case 'BR':
                             $years = range(2014, $year, 2);
                             break;
                         case 'US':
                             $years = range(1788, $year, 4);
                             break;
                     }
                     if (in_array($year, $years)) {
                         $rule = str_replace('%ELECTION', $year, $country_holiday['rule']);
                     } else {
                         $rule = false;
                     }
                 } else {
                     $rule = $country_holiday['rule'] . ' ' . $year;
                 }
                 if ($rule) {
                     $calculated_date = date('Y-m-d', strtotime($rule));
                     if (!isset($calculated_holidays[$calculated_date])) {
                         $calculated_holidays[$calculated_date] = [];
                     }
                     $calculated_holidays[$calculated_date][] = ['name' => $country_holiday['name'], 'country' => $country, 'date' => $calculated_date];
                 }
             }
             $country_holidays = $calculated_holidays;
             ksort($country_holidays);
             foreach ($country_holidays as $date_key => $date_holidays) {
                 usort($date_holidays, function ($a, $b) {
                     $a = $a['name'];
                     $b = $b['name'];
                     if ($a == $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 $country_holidays[$date_key] = $date_holidays;
             }
             if ($this->cache) {
                 $this->cache->setex($cache_key, 3600, serialize($country_holidays));
             }
         }
         $return[$year] = $country_holidays;
     }
     return $return;
 }
 /**
  * Compile a list of holydays for a given year
  * @staticvar array $holidays
  * @param integer $year
  * @return array $holidays for given year
  */
 public static function get_holidays($year = 0)
 {
     static $holidays = array();
     $year = $year ? $year : date('Y');
     if (isset($holidays[$year])) {
         return $holidays[$year];
     }
     $easter_day = easter_days($year);
     $maundy_thursday = $easter_day - 3;
     $holidays[$year] = array(date('Y-m-d', mktime(0, 0, 0, 12, 25, $year - 1)), date('Y-m-d', mktime(0, 0, 0, 12, 26, $year - 1)), date('Y-m-d', mktime(0, 0, 0, 1, 1, $year)), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + $maundy_thursday * 86400), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + ($maundy_thursday + 1) * 86400), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + ($easter_day + 1) * 86400), date('Y-m-d', mktime(0, 0, 0, 5, 1, $year)), date('Y-m-d', mktime(0, 0, 0, 5, 17, $year)), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + ($easter_day + 39) * 86400), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + ($easter_day + 49) * 86400), date('Y-m-d', mktime(0, 0, 0, 3, 21, $year) + ($easter_day + 50) * 86400), date('Y-m-d', mktime(0, 0, 0, 12, 25, $year)), date('Y-m-d', mktime(0, 0, 0, 12, 26, $year)));
     return $holidays[$year];
 }
Beispiel #28
0
 /**
  * When's Easter (Påskdagen)?
  *     Closest sunday after the fullmoon that occours closest on or after 21 mars (in Sweden).
  *
  * @return Carbon
  */
 protected function holidayEaster()
 {
     if ($this->holidays['easter'] !== null) {
         return $this->holidays['easter'];
     }
     $date = DateTime::createFromFormat('Y-m-d H:i:s', $this->year . '-03-21 00:00:00');
     $date->add(new DateInterval('P' . easter_days($this->year) . 'D'));
     $this->holidays['easter'] = $date;
     return $date;
 }
Beispiel #29
0
 public function getEasterMondayBankHoliday($date = null)
 {
     $date = $this->getDate($date);
     $easter_monday_bank_holiday = (new static())->parse("{$date->year}-03-21")->addDays(easter_days($date->year) + 1)->toDateString();
     return $easter_monday_bank_holiday;
 }
* @package hjw calendar Extension
* @copyright (c) 2015 calendar
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
if (!defined('IN_PHPBB')) {
    exit;
}
$sql = 'SELECT *
	FROM ' . CALENDAR_SPECIAL_DAYS_TABLE . '
	ORDER by id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
    if ($row['show_on']) {
        if (!$row['date'] && $row['name'] != 'Advent' && $row['name'] != 'Buß- und Bettag') {
            $sp = easter_days($year) + 21 + (int) $row['eastern'];
            if ($row['big'] == 1) {
                $row['name'] = '<b>' . $row['name'] . '</b>';
            }
            $special_day[date('n', mktime(0, 0, 0, 3, $sp, $year))][date('j', mktime(0, 0, 0, 3, $sp, $year))] = $row['name'];
            $sd_color[date('n', mktime(0, 0, 0, 3, $sp, $year))][date('j', mktime(0, 0, 0, 3, $sp, $year))] = $row['color'];
            $sd_bcolor[date('n', mktime(0, 0, 0, 3, $sp, $year))][date('j', mktime(0, 0, 0, 3, $sp, $year))] = $row['bcolor'];
        }
        if ($row['big'] == 1) {
            $row['name'] = '<b>' . $row['name'] . '</b>';
        }
        if ($row['date']) {
            $sp_date = explode('.', $row['date']);
            $special_day[(int) $sp_date[1]][(int) $sp_date[0]] = $row['name'];
            $sd_color[(int) $sp_date[1]][(int) $sp_date[0]] = $row['color'];
            $sd_bcolor[(int) $sp_date[1]][(int) $sp_date[0]] = $row['bcolor'];