本文整理汇总了PHP中is_leap_year函数的典型用法代码示例。如果您正苦于以下问题:PHP is_leap_year函数的具体用法?PHP is_leap_year怎么用?PHP is_leap_year使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_leap_year函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: week2ymd
function week2ymd($y, $week)
{
$jan_one_dow_m1 = (ymd2rd($y, 1, 1) + 6) % 7;
if ($jan_one_dow_m1 < 4) {
$week--;
}
$day_of_year = $week * 7 - $jan_one_dow_m1;
$leap_year = is_leap_year($y);
if ($day_of_year < 1) {
$y--;
$day_of_year = ($leap_year ? 366 : 365) + $day_of_year;
}
if ($leap_year) {
$ref = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335);
} else {
$ref = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
}
$m = 0;
for ($i = count($ref); $i > 0; $i--) {
if ($day_of_year > $ref[$i - 1]) {
$m = $i;
break;
}
}
return array($y, $m, $day_of_year - $ref[$m - 1]);
}
示例2: indexAction
public function indexAction($request)
{
if (is_leap_year($request->attributes->get('year'))) {
return new Response('Yep, this is a leap year!');
}
return new Response('Nope, this is not a leap year.');
}
示例3: indexAction
public function indexAction($year)
{
if (is_leap_year($year)) {
return new Response('Yep, this is a leap year!');
}
return new Response('Nope, this is not a leap year.');
}
示例4: get_week_number
function get_week_number($timestamp)
{
$d = getdate($timestamp);
$days = iso_week_days($d["yday"], $d["wday"]);
if ($days < 0) {
$d["yday"] += 365 + is_leap_year(--$d["year"]);
$days = iso_week_days($d["yday"], $d["wday"]);
} else {
$d["yday"] -= 365 + is_leap_year($d["year"]);
$d2 = iso_week_days($d["yday"], $d["wday"]);
if (0 <= $d2) {
$days = $d2;
}
}
return (int) ($days / 7) + 2;
}
示例5: roll_calendar
function roll_calendar($calendar_id, $rollover_id)
{
$next_y = UserSyear() + 1;
$cal_RET = DBGet(DBQuery('SELECT DATE_FORMAT(MIN(SCHOOL_DATE),\'%c\') AS START_MONTH,DATE_FORMAT(MIN(SCHOOL_DATE),\'%e\') AS START_DAY,DATE_FORMAT(MIN(SCHOOL_DATE),\'%Y\') AS START_YEAR,
DATE_FORMAT(MAX(SCHOOL_DATE),\'%c\') AS END_MONTH,DATE_FORMAT(MAX(SCHOOL_DATE),\'%e\') AS END_DAY,DATE_FORMAT(MAX(SCHOOL_DATE),\'%Y\') AS END_YEAR FROM attendance_calendar WHERE CALENDAR_ID=' . $rollover_id . ''));
$min_month = $cal_RET[1]['START_MONTH'];
$min_day = $cal_RET[1]['START_DAY'];
$min_year = $cal_RET[1]['START_YEAR'] + 1;
$max_month = $cal_RET[1]['END_MONTH'];
$max_day = $cal_RET[1]['END_DAY'];
$max_year = $cal_RET[1]['END_YEAR'] + 1;
$begin = mktime(0, 0, 0, $min_month, $min_day, $min_year) + 43200;
$end = mktime(0, 0, 0, $max_month, $max_day, $max_year) + 43200;
$day_RET = DBGet(DBQuery('SELECT SCHOOL_DATE FROM attendance_calendar WHERE CALENDAR_ID=\'' . $rollover_id . '\' ORDER BY SCHOOL_DATE LIMIT 0, 7'));
foreach ($day_RET as $day) {
$weekdays[date('w', strtotime($day['SCHOOL_DATE']))] = date('w', strtotime($day['SCHOOL_DATE']));
}
$weekday = date('w', $begin);
for ($i = $begin; $i <= $end; $i += 86400) {
if ($weekdays[$weekday] != '') {
if (is_leap_year($next_y)) {
$previous_year_day = $i - 31622400;
} else {
$previous_year_day = $i - 31536000;
}
$previous_RET = DBGet(DBQuery('SELECT COUNT(SCHOOL_DATE) AS SCHOOL FROM attendance_calendar WHERE SCHOOL_DATE=\'' . date('Y-m-d', $previous_year_day) . '\' AND CALENDAR_ID=\'' . $rollover_id . '\''));
if ($previous_RET[1]['SCHOOL'] == 0) {
$prev_weekday = date('w', $previous_year_day);
if ($weekdays[$prev_weekday] == '') {
DBQuery('INSERT INTO attendance_calendar (SYEAR,SCHOOL_ID,SCHOOL_DATE,MINUTES,CALENDAR_ID) values(\'' . $next_y . '\',\'' . UserSchool() . '\',\'' . date('Y-m-d', $i) . '\',\'999\',\'' . $calendar_id . '\')');
}
} else {
DBQuery('INSERT INTO attendance_calendar (SYEAR,SCHOOL_ID,SCHOOL_DATE,MINUTES,CALENDAR_ID) values(\'' . $next_y . '\',\'' . UserSchool() . '\',\'' . date('Y-m-d', $i) . '\',\'999\',\'' . $calendar_id . '\')');
}
}
$weekday++;
if ($weekday == 7) {
$weekday = 0;
}
}
}
示例6: is_leap_year
<?php
use Symfony\Component\Routing;
use Symfony\Component\HttpFoundation\Response;
function is_leap_year($year = null)
{
if (null === $year) {
$year = date('Y');
}
return 0 == $year % 400 || 0 == $year % 4 && 0 != $year % 100;
}
$routes = new Routing\RouteCollection();
$routes->add('leap_year', new Routing\Route('/is_leap_year/{year}', array('year' => null, '_controller' => function ($request) {
if (is_leap_year($request->attributes->get('year'))) {
return new Response('Yep, this is a leap year!');
}
return new Response('Nope, this is not a leap year.');
})));
return $routes;
示例7: get_month_length
function get_month_length($year, $month)
{
$days_number = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$days_number[2] = is_leap_year($year) ? 29 : 28;
return $days_number[(int) $month];
}
示例8:
case 4:
case 7:
case 10: $quarterday = $monthday; break;
case 2:
case 5:
case 8:
case 11: $quarterday = $monthday + 100; break;
default: $quarterday = $monthday + 200; break;
}
if ($month > 6)
$halfyear = $monthday + ($month - 7) * 100;
else
$halfyear = $monthday + ($month - 1) * 100;
if (is_leap_year($year) && $yearday > 31 + 28)
$yearday -= 1;
$suspension_percentage = $CONFIG['finances']['suspension_percentage'];
if ($taxes = $LMS->GetTaxes($reportday, $reportday))
{
foreach($taxes as $taxidx => $tax)
{
$list1 = $DB->GetAllByKey('SELECT a.customerid AS id, '.$DB->Concat('UPPER(lastname)',"' '",'c.name').' AS customername, '
.$DB->Concat('city',"' '",'address').' AS address, ten,
SUM((((((100 - a.pdiscount) * t.value) / 100) - a.vdiscount) *
((CASE a.suspended WHEN 0 THEN 100.0 ELSE '.$suspension_percentage.' END) / 100))
* (CASE a.period
WHEN '.YEARLY.' THEN 12
WHEN '.HALFYEARLY.' THEN 6
示例9: iterate
//.........这里部分代码省略.........
// remove leading zeros
$minute = (int) $minute;
$second = (int) $second;
}
// we initialize the timeset
if ($timeset == null) {
if ($this->freq < self::HOURLY) {
// daily, weekly, monthly or yearly
// we don't need to calculate a new timeset
$timeset = $this->timeset;
} else {
// initialize empty if it's not going to occurs on the first iteration
if ($this->freq >= self::HOURLY && $this->byhour && !in_array($hour, $this->byhour) || $this->freq >= self::MINUTELY && $this->byminute && !in_array($minute, $this->byminute) || $this->freq >= self::SECONDLY && $this->bysecond && !in_array($second, $this->bysecond)) {
$timeset = array();
} else {
$timeset = $this->getTimeSet($hour, $minute, $second);
}
}
}
// while (true) {
$max_cycles = self::$REPEAT_CYCLES[$this->freq <= self::DAILY ? $this->freq : self::DAILY];
for ($i = 0; $i < $max_cycles; $i++) {
// 1. get an array of all days in the next interval (day, month, week, etc.)
// we filter out from this array all days that do not match the BYXXX conditions
// to speed things up, we use days of the year (day numbers) instead of date
if ($dayset === null) {
// rebuild the various masks and converters
// these arrays will allow fast date operations
// without relying on date() methods
if (empty($masks) || $masks['year'] != $year || $masks['month'] != $month) {
$masks = array('year' => '', 'month' => '');
// only if year has changed
if ($masks['year'] != $year) {
$masks['leap_year'] = is_leap_year($year);
$masks['year_len'] = 365 + (int) $masks['leap_year'];
$masks['next_year_len'] = 365 + is_leap_year($year + 1);
$masks['weekday_of_1st_yearday'] = date_create($year . "-01-01 00:00:00")->format('N');
$masks['yearday_to_weekday'] = array_slice(self::$WEEKDAY_MASK, $masks['weekday_of_1st_yearday'] - 1);
if ($masks['leap_year']) {
$masks['yearday_to_month'] = self::$MONTH_MASK_366;
$masks['yearday_to_monthday'] = self::$MONTHDAY_MASK_366;
$masks['yearday_to_monthday_negative'] = self::$NEGATIVE_MONTHDAY_MASK_366;
$masks['last_day_of_month'] = self::$LAST_DAY_OF_MONTH_366;
} else {
$masks['yearday_to_month'] = self::$MONTH_MASK;
$masks['yearday_to_monthday'] = self::$MONTHDAY_MASK;
$masks['yearday_to_monthday_negative'] = self::$NEGATIVE_MONTHDAY_MASK;
$masks['last_day_of_month'] = self::$LAST_DAY_OF_MONTH;
}
if ($this->byweekno) {
$this->buildWeeknoMask($year, $month, $day, $masks);
}
}
// everytime month or year changes
if ($this->byweekday_nth) {
$this->buildNthWeekdayMask($year, $month, $day, $masks);
}
$masks['year'] = $year;
$masks['month'] = $month;
}
// calculate the current set
$dayset = $this->getDaySet($year, $month, $day, $masks);
$filtered_set = array();
// filter out the days based on the BY*** rules
foreach ($dayset as $yearday) {
if ($this->bymonth && !in_array($masks['yearday_to_month'][$yearday], $this->bymonth)) {
示例10: daysUntilNextBirthday
function daysUntilNextBirthday($birthday)
{
$today = date("Y-m-d");
$btsString = substr($today, 0, 4) . "-" . substr($birthday, 5);
$bts = strtotime($btsString);
$ts = time();
if ($bts < $ts) {
$bts = strtotime(date("y", strtotime("+1 year")) . "-" . substr($birthday, 5));
}
$days = ceil(($bts - $ts) / 86400);
//Full year correction, and leap year correction
$includesLeap = FALSE;
if (substr($birthday, 5, 2) < 3) {
//Born in January or February, so check if this year is a leap year
$includesLeap = is_leap_year(substr($today, 0, 4));
} else {
//Otherwise, check next year
$includesLeap = is_leap_year(substr($today, 0, 4) + 1);
}
if ($includesLeap == TRUE and $days == 366) {
$days = 0;
} else {
if ($includesLeap == FALSE and $days == 365) {
$days = 0;
}
}
return $days;
}
示例11: is_leap_year
<?php
// example.com/src/app.php
use Symfony\Component\Routing;
use Symfony\Component\HttpFoundation\Response;
function is_leap_year($year = null)
{
if (null === $year || !is_int($year)) {
$year = date('Y');
}
// var_dump($year);die;
return 0 === $year % 400 || 0 === $year % 4 && 0 !== $year % 100;
}
$routes = new Routing\RouteCollection();
$routes->add('leap_year', new Routing\Route('/is_leap_year/{year}', array('year' => null, '_controller' => function ($request) {
$year = $request->attributes->get('year');
if (is_leap_year($year)) {
return new Response('Yep, this is a leap year!');
}
return new Response('Nope, this is not a leap year.');
})));
return $routes;
示例12: jewishtojd
$jd = jewishtojd($hmnum, $hd, $hy);
$greg = jdtogregorian($jd);
$debug = $greg;
list($gm, $gd, $gy) = explode("/", $greg, 3);
}
// remove leading zeros, if any
if ($gm[0] == "0") {
$gm = $gm[1];
}
if ($gd[0] == "0") {
$gd = $gd[1];
}
$dow = jddayofweek($jd, 2);
if (strncmp("Adar", $hm, 4) == 0 && !is_leap_year($hy)) {
$hm = "Adar";
} elseif ($hm == "Adar" && is_leap_year($hy)) {
$hm = "Adar1";
}
$month_name = $hmstr_to_hebcal[$hm];
$hebrew = build_hebrew_date($month_name, $hd, $hy);
if ($type == "g2h") {
$first = "{$dow}, {$gd} " . $MoY_long[$gm] . " " . sprintf("%04d", $gy);
$second = format_hebrew_date($hd, $hm, $hy);
$header_hebdate = $second;
} else {
$first = format_hebrew_date($hd, $hm, $hy);
$second = "{$dow}, {$gd} " . $MoY_long[$gm] . " " . sprintf("%04d", $gy);
$header_hebdate = $first;
}
$events = array();
if ($gy >= 1900 && $gy <= 2099) {
示例13: Redirect
Redirect($dirurl, false);
}
if (!is_numeric($_POST["year2"])) {
Redirect($dirurl, false);
}
if (!is_numeric($_POST["year3"])) {
Redirect($dirurl, false);
}
if (!is_numeric($_POST["year4"])) {
Redirect($dirurl, false);
}
switch ($m) {
case 'JAN':
break;
case 'FEB':
if (is_leap_year($y)) {
if ($_POST["day1"] == 3) {
Redirect($dirurl, false);
}
} else {
if ($_POST["day1"] == 3) {
Redirect($dirurl, false);
}
if ($_POST["day1"] == 2 && $_POST["day2"] > 8) {
Redirect($dirurl, false);
}
}
break;
case 'MAR':
break;
case 'APR':
示例14: array
* A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
*
* How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
*/
$given_date = '1 Jan 1900';
$weekday = 2;
$sundays = 0;
$months = array(1 => 31, 2 => 28, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31);
$date_arr = explode(' ', $given_date);
$day = $date_arr[0];
$month = date('n', strtotime($date_arr[1]));
$year = $date_arr[2];
for ($y = $year + 1; $y < 2001; $y++) {
for ($i = $month; $i < 13; $i++) {
$days = $months[$i];
if ($i == 2 && is_leap_year($y)) {
$days++;
}
for ($d = 1; $d <= $days; $d++) {
if ($weekday == 7 && $d == 1) {
$sundays++;
}
if ($weekday == 7) {
$weekday = 0;
}
$weekday++;
}
}
$month = 1;
}
echo $sundays;