示例#1
0
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
0
 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
0
 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
0
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
0
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
0
<?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;
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
0
文件: print.php 项目: rzt/lms
			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
0
 /**
  * This is the main method, where all of the magic happens.
  *
  * This method is a generator that works for PHP 5.3/5.4 (using static variables)
  *
  * The main idea is: a brute force made fast by not relying on date() functions
  * 
  * There is one big loop that examines every interval of the given frequency
  * (so every day, every week, every month or every year), constructs an
  * array of all the yeardays of the interval (for daily frequencies, the array
  * only has one element, for weekly 7, and so on), and then filters out any
  * day that do no match BYXXX parts.
  *
  * The algorithm does not try to be "smart" in calculating the increment of
  * the loop. That is, for a rule like "every day in January for 10 years"
  * the algorithm will loop through every day of the year, each year, generating
  * some 3650 iterations (+ some to account for the leap years).
  * This is a bit counter-intuitive, as it is obvious that the loop could skip
  * all the days in February till December since they are never going to match.
  *
  * Fortunately, this approach is still super fast because it doesn't rely
  * on date() or DateTime functions, and instead does all the date operations
  * manually, either arithmetically or using arrays as converters.
  *
  * Another quirk of this approach is that because the granularity is by day,
  * higher frequencies (hourly, minutely and secondly) have to have
  * their own special loops within the main loop, making the whole thing quite
  * convoluted.
  * Moreover, at such frequencies, the brute-force approach starts to really
  * suck. For example, a rule like
  * "Every minute, every Jan 1st between 10:00 and 10:59, for 10 years" 
  * requires a tremendous amount of useless iterations to jump from Jan 1st 10:59
  * at year 1 to Jan 1st 10.00 at year 2.
  *
  * In order to make a "smart jump", we would have to have a way to determine
  * the gap between the next occurence arithmetically. I think that would require
  * to analyze each "BYXXX" rule part that "Limit" the set (see the RFC page 43)
  * at the given frequency. For example, a YEARLY frequency doesn't need "smart
  * jump" at all; MONTHLY and WEEKLY frequencies only need to check BYMONTH;
  * DAILY frequency needs to check BYMONTH, BYMONTHDAY and BYDAY, and so on.
  * The check probably has to be done in reverse order, e.g. for DAILY frequencies
  * attempt to jump to the next weekday (BYDAY) or next monthday (BYMONTHDAY)
  * (I don't know yet which one first), and then if that results in a change of
  * month, attempt to jump to the next BYMONTH, and so on.
  *
  * @param $reset (bool) Whether to restart the iteration, or keep going
  * @return \DateTime|null
  */
 protected function iterate($reset = false)
 {
     // for readability's sake, and because scope of the variables should be local anyway
     $year =& $this->_year;
     $month =& $this->_month;
     $day =& $this->_day;
     $hour =& $this->_hour;
     $minute =& $this->_minute;
     $second =& $this->_second;
     $dayset =& $this->_dayset;
     $masks =& $this->_masks;
     $timeset =& $this->_timeset;
     $dtstart =& $this->_dtstart;
     $total =& $this->_total;
     $use_cache =& $this->_use_cache;
     if ($reset) {
         $this->_year = $this->_month = $this->_day = null;
         $this->_hour = $this->_minute = $this->_second = null;
         $this->_dayset = $this->_masks = $this->_timeset = null;
         $this->_dtstart = null;
         $this->_total = 0;
         $this->_use_cache = true;
         reset($this->cache);
     }
     // go through the cache first
     if ($use_cache) {
         while (($occurrence = current($this->cache)) !== false) {
             // echo "Cache hit\n";
             $dtstart = $occurrence;
             next($this->cache);
             $total += 1;
             return clone $occurrence;
             // since DateTime is not immutable, avoid any problem
         }
         reset($this->cache);
         // now set use_cache to false to skip the all thing on next iteration
         // and start filling the cache instead
         $use_cache = false;
         // if the cache as been used up completely and we now there is nothing else
         if ($total === $this->total) {
             // echo "Cache used up, nothing else to compute\n";
             return null;
         }
         // echo "Cache used up with occurrences remaining\n";
         if ($dtstart) {
             $dtstart = clone $dtstart;
             // since DateTime is not immutable, avoid any problem
             // so we skip the last occurrence of the cache
             if ($this->freq === self::SECONDLY) {
                 $dtstart->modify('+' . $this->interval . 'second');
             } else {
                 $dtstart->modify('+1second');
             }
         }
     }
     // stop once $total has reached COUNT
     if ($this->count && $total >= $this->count) {
         $this->total = $total;
         return null;
     }
     if ($dtstart === null) {
         $dtstart = clone $this->dtstart;
     }
     if ($year === null) {
         if ($this->freq === self::WEEKLY) {
             // we align the start date to the WKST, so we can then
             // simply loop by adding +7 days. The Python lib does some
             // calculation magic at the end of the loop (when incrementing)
             // to realign on first pass.
             $tmp = clone $dtstart;
             $tmp->modify('-' . pymod($dtstart->format('N') - $this->wkst, 7) . 'days');
             list($year, $month, $day, $hour, $minute, $second) = explode(' ', $tmp->format('Y n j G i s'));
             unset($tmp);
         } else {
             list($year, $month, $day, $hour, $minute, $second) = explode(' ', $dtstart->format('Y n j G i s'));
         }
         // 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)) {
                     continue;
                 }
                 if ($this->byweekno && !isset($masks['yearday_is_in_weekno'][$yearday])) {
                     continue;
                 }
                 if ($this->byyearday) {
                     if ($yearday < $masks['year_len']) {
                         if (!in_array($yearday + 1, $this->byyearday) && !in_array(-$masks['year_len'] + $yearday, $this->byyearday)) {
                             continue;
                         }
                     } else {
                         // if ( ($yearday >= $masks['year_len']
                         if (!in_array($yearday + 1 - $masks['year_len'], $this->byyearday) && !in_array(-$masks['next_year_len'] + $yearday - $mask['year_len'], $this->byyearday)) {
                             continue;
                         }
                     }
                 }
                 if (($this->bymonthday || $this->bymonthday_negative) && !in_array($masks['yearday_to_monthday'][$yearday], $this->bymonthday) && !in_array($masks['yearday_to_monthday_negative'][$yearday], $this->bymonthday_negative)) {
                     continue;
                 }
                 if (($this->byweekday || $this->byweekday_nth) && !in_array($masks['yearday_to_weekday'][$yearday], $this->byweekday) && !isset($masks['yearday_is_nth_weekday'][$yearday])) {
                     continue;
                 }
                 $filtered_set[] = $yearday;
             }
             $dayset = $filtered_set;
             // if BYSETPOS is set, we need to expand the timeset to filter by pos
             // so we make a special loop to return while generating
             if ($this->bysetpos && $timeset) {
                 $filtered_set = array();
                 foreach ($this->bysetpos as $pos) {
                     $n = count($timeset);
                     if ($pos < 0) {
                         $pos = $n * count($dayset) + $pos;
                     } else {
                         $pos = $pos - 1;
                     }
                     $div = (int) ($pos / $n);
                     // daypos
                     $mod = $pos % $n;
                     // timepos
                     if (isset($dayset[$div]) && isset($timeset[$mod])) {
                         $yearday = $dayset[$div];
                         $time = $timeset[$mod];
                         // used as array key to ensure uniqueness
                         $tmp = $year . ':' . $yearday . ':' . $time[0] . ':' . $time[1] . ':' . $time[2];
                         if (!isset($filtered_set[$tmp])) {
                             $occurrence = \DateTime::createFromFormat('Y z', "{$year} {$yearday}", $this->dtstart->getTimezone());
                             $occurrence->setTime($time[0], $time[1], $time[2]);
                             $filtered_set[$tmp] = $occurrence;
                         }
                     }
                 }
                 sort($filtered_set);
                 $dayset = $filtered_set;
             }
         }
         // 2. loop, generate a valid date, and return the result (fake "yield")
         // at the same time, we check the end condition and return null if
         // we need to stop
         if ($this->bysetpos && $timeset) {
             while (($occurrence = current($dayset)) !== false) {
                 // consider end conditions
                 if ($this->until && $occurrence > $this->until) {
                     $this->total = $total;
                     // save total for count() cache
                     return null;
                 }
                 next($dayset);
                 if ($occurrence >= $dtstart) {
                     // ignore occurrences before DTSTART
                     $total += 1;
                     $this->cache[] = $occurrence;
                     return clone $occurrence;
                     // yield
                 }
             }
         } else {
             // normal loop, without BYSETPOS
             while (($yearday = current($dayset)) !== false) {
                 $occurrence = \DateTime::createFromFormat('Y z', "{$year} {$yearday}", $this->dtstart->getTimezone());
                 while (($time = current($timeset)) !== false) {
                     $occurrence->setTime($time[0], $time[1], $time[2]);
                     // consider end conditions
                     if ($this->until && $occurrence > $this->until) {
                         $this->total = $total;
                         // save total for count() cache
                         return null;
                     }
                     next($timeset);
                     if ($occurrence >= $dtstart) {
                         // ignore occurrences before DTSTART
                         $total += 1;
                         $this->cache[] = $occurrence;
                         return clone $occurrence;
                         // yield
                     }
                 }
                 reset($timeset);
                 next($dayset);
             }
         }
         // 3. we reset the loop to the next interval
         $days_increment = 0;
         switch ($this->freq) {
             case self::YEARLY:
                 // we do not care about $month or $day not existing,
                 // they are not used in yearly frequency
                 $year = $year + $this->interval;
                 break;
             case self::MONTHLY:
                 // we do not care about the day of the month not existing
                 // it is not used in monthly frequency
                 $month = $month + $this->interval;
                 if ($month > 12) {
                     $div = (int) ($month / 12);
                     $mod = $month % 12;
                     $month = $mod;
                     $year = $year + $div;
                     if ($month == 0) {
                         $month = 12;
                         $year = $year - 1;
                     }
                 }
                 break;
             case self::WEEKLY:
                 $days_increment = $this->interval * 7;
                 break;
             case self::DAILY:
                 $days_increment = $this->interval;
                 break;
                 // For the time frequencies, things are a little bit different.
                 // We could just add "$this->interval" hours, minutes or seconds
                 // to the current time, and go through the main loop again,
                 // but since the frequencies are so high and needs to much iteration
                 // it's actually a bit faster to have custom loops and only
                 // call the DateTime method at the very end.
             // For the time frequencies, things are a little bit different.
             // We could just add "$this->interval" hours, minutes or seconds
             // to the current time, and go through the main loop again,
             // but since the frequencies are so high and needs to much iteration
             // it's actually a bit faster to have custom loops and only
             // call the DateTime method at the very end.
             case self::HOURLY:
                 if (empty($dayset)) {
                     // an empty set means that this day has been filtered out
                     // by one of the BYXXX rule. So there is no need to
                     // examine it any further, we know nothing is going to
                     // occur anyway.
                     // so we jump to one iteration right before next day
                     $hour += (int) ((23 - $hour) / $this->interval) * $this->interval;
                 }
                 $found = false;
                 for ($j = 0; $j < self::$REPEAT_CYCLES[self::HOURLY]; $j++) {
                     $hour += $this->interval;
                     $div = (int) ($hour / 24);
                     $mod = $hour % 24;
                     if ($div) {
                         $hour = $mod;
                         $days_increment += $div;
                     }
                     if (!$this->byhour || in_array($hour, $this->byhour)) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $this->total = $total;
                     // save total for count cache
                     return null;
                     // stop the iterator
                 }
                 $timeset = $this->getTimeSet($hour, $minute, $second);
                 break;
             case self::MINUTELY:
                 if (empty($dayset)) {
                     $minute += (int) ((1439 - ($hour * 60 + $minute)) / $this->interval) * $this->interval;
                 }
                 $found = false;
                 for ($j = 0; $j < self::$REPEAT_CYCLES[self::MINUTELY]; $j++) {
                     $minute += $this->interval;
                     $div = (int) ($minute / 60);
                     $mod = $minute % 60;
                     if ($div) {
                         $minute = $mod;
                         $hour += $div;
                         $div = (int) ($hour / 24);
                         $mod = $hour % 24;
                         if ($div) {
                             $hour = $mod;
                             $days_increment += $div;
                         }
                     }
                     if ((!$this->byhour || in_array($hour, $this->byhour)) && (!$this->byminute || in_array($minute, $this->byminute))) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $this->total = $total;
                     // save total for count cache
                     return null;
                     // stop the iterator
                 }
                 $timeset = $this->getTimeSet($hour, $minute, $second);
                 break;
             case self::SECONDLY:
                 if (empty($dayset)) {
                     $second += (int) ((86399 - ($hour * 3600 + $minute * 60 + $second)) / $this->interval) * $this->interval;
                 }
                 $found = false;
                 for ($j = 0; $j < self::$REPEAT_CYCLES[self::SECONDLY]; $j++) {
                     $second += $this->interval;
                     $div = (int) ($second / 60);
                     $mod = $second % 60;
                     if ($div) {
                         $second = $mod;
                         $minute += $div;
                         $div = (int) ($minute / 60);
                         $mod = $minute % 60;
                         if ($div) {
                             $minute = $mod;
                             $hour += $div;
                             $div = (int) ($hour / 24);
                             $mod = $hour % 24;
                             if ($div) {
                                 $hour = $mod;
                                 $days_increment += $div;
                             }
                         }
                     }
                     if ((!$this->byhour || in_array($hour, $this->byhour)) && (!$this->byminute || in_array($minute, $this->byminute)) && (!$this->bysecond || in_array($second, $this->bysecond))) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $this->total = $total;
                     // save total for count cache
                     return null;
                     // stop the iterator
                 }
                 $timeset = $this->getTimeSet($hour, $minute, $second);
                 break;
         }
         // here we take a little shortcut from the Python version, by using DateTime
         if ($days_increment) {
             list($year, $month, $day) = explode('-', date_create("{$year}-{$month}-{$day}")->modify("+ {$days_increment} days")->format('Y-n-j'));
         }
         $dayset = null;
         // reset the loop
     }
     $this->total = $total;
     // save total for count cache
     return null;
     // stop the iterator
 }
示例#10
0
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
0
文件: app.php 项目: litbear/framework
<?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
0
    $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
0
     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
0
 * 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;