note 38924 added to function.strftime
| From: | rickenmeer at hotmail dot com | Date: | Mon, 12 Jan 2004 13:10:34 +0000 |
| Subject: | note 38924 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63348@lists.php.net to get a copy of this message | ||
This override for strftime was created to cope with the date limits on Win32 (1970-2037). Current
mappings and allows you to calculate daylight savings time etc. for 1902-1969, feel free to add more
mappings!
<?PHP
function &strftime ($format = "", $timestamp = false)
{
if ($timestamp >= 0 && $timestamp <= 2147480047)
{ // between 1 Jan 1970 00:00:00 and 19 Jan 2038 03:14:07 GMT
return strftime ($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
);
if ($timestamp < 0)
{
$year = 1969;
while ($timestamp < 0)
{
$days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365;
$timestamp += $days * 86400;
$year--;
}
}
else // if ($timestamp > 2147480047)
{
$year = 2038;
while ($timestamp > 0)
{
$days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365;
$timestamp -= $days * 86400;
$year++;
}
}
foreach ($mappings as $mapping)
if ($year >= $mapping["start"] && $year <= $mapping["end"])
{
$find = Array ("%y", "%Y", "%D");
$replace = Array (substr ($year, -2), $year, "%m/%d/" . substr ($year, -2));
$format =& str_replace ($find, $replace, $format);
$map_from_1970 = mktime (0, 0, 0, 1, 1, $mapping["map"]);
return strftime ($format, $timestamp + $map_from_1970);
}
return "strftime (): Year not mapped yet: " . $year;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.strftime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38924
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38924&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38924&report=yes
Search -- http://master.php.net/manage/user-notes.php