/** * Returns day on which Summer time starts or ends for given year * * The limit (start or end) code can take the following forms: * 5 the fifth of the month * lastSun the last Sunday in the month * lastMon the last Monday in the month * Sun>=8 first Sunday on or after the 8th * Sun<=25 last Sunday on or before the 25th * * @param string $ps_summertimelimitcode code which specifies Summer time * limit day * @param int $pn_month start or end month * @param int $pn_year year for which to calculate Summer * time limit day * * @return int * @access private * @since Method available since Release 1.5.0 */ function getSummerTimeLimitDay($ps_summertimelimitcode, $pn_month, $pn_year) { if (preg_match('/^[0-9]+$/', $ps_summertimelimitcode)) { $hn_day = $ps_summertimelimitcode; } else { if (!isset($ha_daysofweek)) { static $ha_daysofweek = array("Sun" => 0, "Mon" => 1, "Tue" => 2, "Wed" => 3, "Thu" => 4, "Fri" => 5, "Sat" => 6); } if (preg_match('/^last(Sun|Mon|Tue|Wed|Thu|Fri|Sat)$/', $ps_summertimelimitcode, $ha_matches)) { list($hn_nmyear, $hn_nextmonth, $hn_nmday) = explode(" ", Date_Calc::beginOfMonthBySpan(1, $pn_month, $pn_year, "%Y %m %d")); list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::prevDayOfWeek($ha_daysofweek[$ha_matches[1]], $hn_nmday, $hn_nextmonth, $hn_nmyear, "%Y %m %d", false)); // not including // this day if ($hn_month != $pn_month) { // This code happen legitimately if the calendar jumped some days // e.g. in a calendar switch, or the limit day is badly defined: // $hn_day = Date_Calc::getFirstDayOfMonth($pn_month, $pn_year); } } else { if (preg_match('/^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)([><]=)([0-9]+)$/', $ps_summertimelimitcode, $ha_matches)) { if ($ha_matches[2] == "<=") { list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::prevDayOfWeek($ha_daysofweek[$ha_matches[1]], $ha_matches[3], $pn_month, $pn_year, "%Y %m %d", true)); // including // this day if ($hn_month != $pn_month) { $hn_day = Date_Calc::getFirstDayOfMonth($pn_month, $pn_year); } } else { list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::nextDayOfWeek($ha_daysofweek[$ha_matches[1]], $ha_matches[3], $pn_month, $pn_year, "%Y %m %d", true)); // including // this day if ($hn_month != $pn_month) { $hn_day = Date_Calc::daysInMonth($pn_month, $pn_year); } } } } } return $hn_day; }
compare('20001201', Date_Calc::beginOfNextMonth(22, 11, 2000), 'beginOfNextMonth'); compare('20001231', Date_Calc::endOfNextMonth(22, 11, 2000), 'endOfNextMonth'); compare('20001201', Date_Calc::beginOfNextMonth('22', '11', '2000'), 'beginOfNextMonth str'); compare('20001231', Date_Calc::endOfNextMonth('22', '11', '2000'), 'endOfNextMonth str'); compare('19991001', Date_Calc::beginOfMonthBySpan(-13, 11, 2000), 'beginOfMonthBySpan 1'); compare('20001001', Date_Calc::beginOfMonthBySpan(-1, 11, 2000), 'beginOfMonthBySpan 2'); compare('20001101', Date_Calc::beginOfMonthBySpan(0, 11, 2000), 'beginOfMonthBySpan 3'); compare('20001201', Date_Calc::beginOfMonthBySpan(1, 11, 2000), 'beginOfMonthBySpan 4'); compare('20011201', Date_Calc::beginOfMonthBySpan(13, 11, 2000), 'beginOfMonthBySpan 5'); compare('19990101', Date_Calc::beginOfMonthBySpan('-13', '02', '2000'), 'beginOfMonthBySpan 6 str'); compare('19990101', Date_Calc::beginOfMonthBySpan(-13, 2, 2000), 'beginOfMonthBySpan 6'); compare('20000101', Date_Calc::beginOfMonthBySpan(-1, 2, 2000), 'beginOfMonthBySpan 7'); compare('20000201', Date_Calc::beginOfMonthBySpan(0, 2, 2000), 'beginOfMonthBySpan 8'); compare('20000301', Date_Calc::beginOfMonthBySpan(1, 2, 2000), 'beginOfMonthBySpan 9'); compare('20010301', Date_Calc::beginOfMonthBySpan(13, 2, 2000), 'beginOfMonthBySpan 10'); compare('20010301', Date_Calc::beginOfMonthBySpan('13', '02', '2000'), 'beginOfMonthBySpan 10 str'); compare('19991031', Date_Calc::endOfMonthBySpan(-13, 11, 2000), 'endOfMonthBySpan 1'); compare('20001031', Date_Calc::endOfMonthBySpan(-1, 11, 2000), 'endOfMonthBySpan 2'); compare('20001130', Date_Calc::endOfMonthBySpan(0, 11, 2000), 'endOfMonthBySpan 3'); compare('20001231', Date_Calc::endOfMonthBySpan(1, 11, 2000), 'endOfMonthBySpan 4'); compare('20011231', Date_Calc::endOfMonthBySpan(13, 11, 2000), 'endOfMonthBySpan 5'); compare('19990131', Date_Calc::endOfMonthBySpan('-13', '02', '2000'), 'endOfMonthBySpan 6 str'); compare('19990131', Date_Calc::endOfMonthBySpan(-13, 2, 2000), 'endOfMonthBySpan 6'); compare('20000131', Date_Calc::endOfMonthBySpan(-1, 2, 2000), 'endOfMonthBySpan 7'); compare('20000229', Date_Calc::endOfMonthBySpan(0, 2, 2000), 'endOfMonthBySpan 8'); compare('20000331', Date_Calc::endOfMonthBySpan(1, 2, 2000), 'endOfMonthBySpan 9'); compare('20010331', Date_Calc::endOfMonthBySpan(13, 2, 2000), 'endOfMonthBySpan 10'); compare('20010331', Date_Calc::endOfMonthBySpan('13', '02', '2000'), 'endOfMonthBySpan 10 str'); compare(3, Date_Calc::firstOfMonthWeekday(11, 2000), 'firstOfMonthWeekday'); compare(3, Date_Calc::firstOfMonthWeekday('11', '2000'), 'firstOfMonthWeekday str'); compare('20050101', Date_Calc::NWeekdayOfMonth(1, 6, 1, 2005), 'NWeekdayOfMonth 161');