com php-src: Fixed "Forward Transition" construction of DateTime objects.: ext/date/php_date.c ext/date/tests/forward-transition-con struction.phpt
| From: | Derick Rethans | Date: | Thu, 28 Nov 2013 12:02:35 +0000 |
| Subject: | com php-src: Fixed "Forward Transition" construction of DateTime objects.: ext/date/php_date.c ext/date/tests/forward-transition-con struction.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74138@lists.php.net to get a copy of this message | ||
Commit: 44a9e6b4843de686eab2e2bfa66bdf17ed685d7e
Author: Derick Rethans <github@derickrethans.nl> Sun, 31 Mar 2013 18:11:35 +0100
Parents: fb0c2cf2245838cba1bd9318925d67a127c7b085
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=44a9e6b4843de686eab2e2bfa66bdf17ed685d7e
Log:
Fixed "Forward Transition" construction of DateTime objects.
This fixes the issue in
https://wiki.php.net/rfc/datetime_and_daylight_saving_time#forward_transitions
There is a period during transition to DST where a time (such as 02:30) does
not exist. PHP already calculated the correct timestamp for this, but failed to
"rounded forward" to the existing correct hour value.
Changed paths:
M ext/date/php_date.c
A ext/date/tests/forward-transition-construction.phpt
Diff:
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index b7da07c..05ac672 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2487,6 +2487,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char
*time_str,
timelib_fill_holes(dateobj->time, now, TIMELIB_NO_CLONE);
timelib_update_ts(dateobj->time, tzi);
+ timelib_update_from_sse(dateobj->time);
dateobj->time->have_relative = 0;
diff --git a/ext/date/tests/forward-transition-construction.phpt
b/ext/date/tests/forward-transition-construction.phpt
new file mode 100644
index 0000000..8f195a5
--- /dev/null
+++ b/ext/date/tests/forward-transition-construction.phpt
@@ -0,0 +1,27 @@
+--TEST--
+Test for Date/Time construction during a forward DST transition
+--FILE--
+<?php
+date_default_timezone_set('America/New_York');
+
+$date = new DateTime('2010-03-14 01:30:00');
+echo $date->format('Y-m-d H:i:s T/e - U') . "\n";
+
+$date = new DateTime('2010-03-14 02:00:00');
+echo $date->format('Y-m-d H:i:s T/e - U') . "\n";
+
+$date = new DateTime('2010-03-14 02:30:00');
+echo $date->format('Y-m-d H:i:s T/e - U') . "\n";
+
+$date = new DateTime('2010-03-14 03:00:00');
+echo $date->format('Y-m-d H:i:s T/e - U') . "\n";
+
+$date = new DateTime('2010-03-14 03:30:00');
+echo $date->format('Y-m-d H:i:s T/e - U') . "\n";
+?>
+--EXPECT--
+2010-03-14 01:30:00 EST/America/New_York - 1268548200
+2010-03-14 03:00:00 EDT/America/New_York - 1268550000
+2010-03-14 03:30:00 EDT/America/New_York - 1268551800
+2010-03-14 03:00:00 EDT/America/New_York - 1268550000
+2010-03-14 03:30:00 EDT/America/New_York - 1268551800