note 38924 deleted from function.strftime by derick

From: Date: Sat, 04 Nov 2006 10:44:12 +0000
Subject: note 38924 deleted from function.strftime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119384@lists.php.net to get a copy of this message
Note Submitter: rickenmeer at hotmail dot com ---- 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; } ?>

« previous php.notes (#119384) next »