本文整理汇总了PHP中easter_days函数的典型用法代码示例。如果您正苦于以下问题:PHP easter_days函数的具体用法?PHP easter_days怎么用?PHP easter_days使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了easter_days函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isHoliday
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);
}
示例2: getEasterDates
/**
* 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);
}
示例3: calculateHolidays
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;
}
示例4: getEasterMonday
/**
* 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);
}
示例5: HolidayDataProvider
/**
* 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;
}
示例6: is_market_closed
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');
}
示例7: contains
/**
* @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;
}
示例8: isWorkDay
/**
* 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;
}
示例9: getEasterDate
/**
* 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'));
}
示例10: working_days_from
/**
* 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;
//.........这里部分代码省略.........
示例11: dateIsTargetDay
/**
* 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;
}
示例12: getEasterDatetime
/**
*
* @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"));
}
示例13: getEasterForDateTime
/**
* 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'));
}
示例14: sCreateHolidaysTable
/**
* 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);
}
}
示例15: daysOffSwe
/**
* 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;
}