function adddays($tm, $days) { $mdays = array(1 => 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $time = $tm; if (isleapyear($time[0])) { $mdays[2] = 29; } if ($days > 0) { for ($i = 0; $i < $days; $i++) { if ($time[2] < $mdays[$time[1]]) { $time[2]++; } else { $time[2] = 1; $time[1]++; if ($time[1] > 12) { $time[1] = 1; $time[0]++; if (isleapyear($time[0])) { $mdays[2] = 29; } else { $mdays[2] = 28; } } } } } else { for ($i = 0; $i < -$days; $i++) { if ($time[2] > 1) { $time[2]--; } else { $time[1]--; if ($time[1] < 1) { $time[0]--; if (isleapyear($time[0])) { $mdays[2] = 29; } else { $mdays[2] = 28; } $time[1] = 12; } $time[2] = $mdays[$time[1]]; } } } return $time; }
/** * Get the last month's day number * @param {number} year * @param {number} month * @return {number} */ function getLastMonthDayNumber($year, $month) { if ($month == 2 && isleapyear($year)) { return 29; } $mdays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); return $mdays[$month - 1]; }
protected function getDatesByWeek($week, $year) { global $locale_info; $startweekday = 0; if ($locale_info["LOCALE_IFIRSTDAYOFWEEK"] > 0) { $startweekday = 7 - $locale_info["LOCALE_IFIRSTDAYOFWEEK"]; } $L = isleapyear($year) ? 1 : 0; $months = array(31, 28 + $L, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $total_days = ($week - 1) * 7; $i = 0; $sum = 0; while ($sum <= $total_days) { $sum += $months[$i++]; } $sum -= $months[$i - 1]; $month = $i; $day = $total_days - $sum; $day_of_week = getdayofweek(array($year, $month, $day)); if ($day_of_week == 0) { $day_of_week = 7; } $day = $day - ($day_of_week - 1) - $startweekday; $dates = array(); $dates[0] = getYMDdate(mktime(0, 0, 0, $month, $day, $year)); $dates[1] = getYMDdate(mktime(1, 1, 1, $month, $day + 6, $year)); return $dates; }