/** * Returns date of the first day of the month in the number of months * from the given date * * @param int $months the number of months from the date provided. * Positive numbers go into the future. * Negative numbers go into the past. * 0 is the month presented in $month. * @param string $month the month, default is current local month * @param string $year the year in four digit format, default is the * current local year * @param string $format the string indicating how to format the output * * @return string the date in the desired format * @access public * @static * @since Method available since Release 1.4.4 */ function beginOfMonthBySpan($months = 0, $month = 0, $year = null, $format = DATE_CALC_FORMAT) { if (is_null($year)) { $year = Date_Calc::dateNow('%Y'); } if (empty($month)) { $month = Date_Calc::dateNow('%m'); } return Date_Calc::addMonths($months, Date_Calc::getFirstDayOfMonth($month, $year), $month, $year, $format); }
/** * 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; }