date according to ISO 8601-1988
function is_leap_year($year) {
if ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
return 1;
} else {
return 0;
}
}
/*
#define ISO_WEEK_START_WDAY 1 // Monday
#define ISO_WEEK1_WDAY 4 // Thursday
#define YDAY_MINIMUM (-366)
int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
return (yday
- (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7
+ ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY);
*/
function iso_week_days($yday, $wday) {
return $yday - (($yday - $wday + 382) % 7) + 3;
}
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) {
/* $d["year"]++; */
$days = $d2;
}
}
return (int)($days / 7) + 1;
}
?>