Pour les dates extrêmes, tu peux encapsuler la fonction strftime dans une fonction qui va te permettre de mapper les années hors limites vers celles supportées par la fonction.
Petit exemple de fonction
Petit exemple de fonction
Code PHP :
<?php
function strftime_ext($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
Array ("start" => 2038, "end" => 2091, "map" => 1982), // 2038-2091 = 1982-2035
//add additional mapping here
);
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;
}
Et voila comment revenir à la prog...