note 38922 deleted from function.date by kennyt

From: Date: Sun, 18 Jul 2004 17:27:51 +0000
Subject: note 38922 deleted from function.date by kennyt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73512@lists.php.net to get a copy of this message
Note Submitter: rickenmeer@hotmail.com ---- An override for date () using mapping, allowing calculation of daylight saving times, weeknumbers, etc. <?PHP function &date ($format = "", $timestamp = false) { if ($timestamp >= 0 && $timestamp <= 2147480047) { // between 1 Jan 1970 00:00:00 and 19 Jan 2038 03:14:07 GMT return date ($format, $timestamp); } $mappings = Array ( Array ("start" => 1902, "end" => 1951, "map" => 1986), // 1902-1951 = 1986-2035 Array ("start" => 1952, "end" => 1969, "map" => 1980), // 1952-1969 = 1980-1997 ); $temp = $timestamp; if ($timestamp < 0) { $year = 1969; while ($temp < 0) { $days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365; $temp += $days * 86400; $year--; } } else // if ($timestamp > 2147480047) { $year = 2038; while ($temp > 0) { $days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365; $temp -= $days * 86400; $year++; } } foreach ($mappings as $mapping) if ($year >= $mapping["start"] && $year <= $mapping["end"]) { $format =& str_replace (Array ("y", "Y"), Array (substr ($year, -2), $year), $format); return date ($format, $temp + mktime (0, 0, 0, 1, 1, $mapping["map"])); } return "date (): Year not mapped yet: " . $year; } ?>

« previous php.notes (#73512) next »