Patch bug51051test.php.txt for Date/time related Bug #51051
Patch version 2010-12-25 01:26 UTC
Return to Bug #51051 |
Download this patch
Patch Revisions:
Developer: danielc@php.net
// http://bugs.php.net/bug.php?id=51051
echo "\nSPRING INTERVALS (add okay, sub does not change hour)\n";
$d = new DateTime('2010-03-14 01:59:59', new DateTimeZone('America/New_York'));
$u = $d->format('U'); // Save timestamp for later.
f($d);
add_interval($d, 'PT1S');
sub_interval($d, 'PT1S');
echo "\nSPRING TIMESTAMPS (works as expected)\n";
process_timestamp($u);
add_timestamp($u, 1);
sub_timestamp($u, 1);
echo "\nFALL INTERVALS (add and sub skip the 1am - 2am redo)\n";
$d = new DateTime('2010-11-07 00:59:59', new DateTimeZone('America/New_York'));
$u = $d->format('U'); // Save timestamp for later.
f($d);
add_interval($d, 'PT1H');
add_interval($d, 'PT1S');
sub_interval($d, 'PT1S');
echo "\nFALL TIMESTAMPS (works as expected)\n";
process_timestamp($u);
add_timestamp($u, 3600);
add_timestamp($u, 1);
add_timestamp($u, 3600);
sub_timestamp($u, 1);
function add_interval($d, $s) {
echo "Adding interval: $s\n";
$i = new DateInterval($s);
$d->add($i);
f($d);
}
function sub_interval($d, $s) {
echo "Subtracting interval: $s\n";
$i = new DateInterval($s);
$d->sub($i);
f($d);
}
function add_timestamp(&$u, $s) {
echo "Adding seconds: $s\n";
$u += $s;
process_timestamp($u);
}
function sub_timestamp(&$u, $s) {
echo "Subtracting seconds: $s\n";
$u -= $s;
process_timestamp($u);
}
function process_timestamp($u) {
$d = new DateTime("@$u");
$d->setTimeZone(new DateTimeZone('America/New_York'));
f($d);
}
function f($d) {
echo $d->format(' c e T I U') . "\n";
}
|