From d70058a139f3a45898e1f270c840fb64ea1a09f0 Mon Sep 17 00:00:00 2001 From: Nate Brunette Date: Wed, 18 Mar 2020 15:04:46 -0500 Subject: [PATCH] Fix #79396: DateTime hour incorrect during DST jump forward When you attempt to set the time to a non-existent time occuring during a DST jump forward, the hour does not move forward correctly. --- NEWS | 4 ++++ ext/date/php_date.c | 1 + .../bug79396-forward-transition-settime.phpt | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ext/date/tests/bug79396-forward-transition-settime.phpt diff --git a/NEWS b/NEWS index 2591b192ac..4778a5c554 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,10 @@ PHP NEWS - CURL: . Fixed bug #79199 (curl_copy_handle() memory leak). (cmb) +- Date: + . Fixed bug #79396 (DateTime hour incorrect during DST jump forward). (Nate + Brunette) + - SimpleXML: . Fixed bug #61597 (SXE properties may lack attributes and content). (cmb) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index bec60aab6d..d0e14e9f4f 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3562,6 +3562,7 @@ static void php_date_time_set(zval *object, zend_long h, zend_long i, zend_long dateobj->time->s = s; dateobj->time->us = ms; timelib_update_ts(dateobj->time, NULL); + timelib_update_from_sse(dateobj->time); } /* }}} */ /* {{{ proto DateTime date_time_set(DateTime object, int hour, int minute[, int second[, int microseconds]]) diff --git a/ext/date/tests/bug79396-forward-transition-settime.phpt b/ext/date/tests/bug79396-forward-transition-settime.phpt new file mode 100644 index 0000000000..95bf2f20b6 --- /dev/null +++ b/ext/date/tests/bug79396-forward-transition-settime.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test for setting Date/Time during a forward DST transition +--FILE-- +setTime(2, 0)->format('Y-m-d H:i:s T/e - U') . "\n"; + +$date = new DateTime('2020-03-08 01:30:00'); +echo $date->setTime(2, 30)->format('Y-m-d H:i:s T/e - U') . "\n"; + +$date = new DateTime('2020-03-08 01:30:00'); +echo $date->setTime(3, 0)->format('Y-m-d H:i:s T/e - U') . "\n"; + +$date = new DateTime('2020-03-08 01:30:00'); +echo $date->setTime(1, 59, 59)->format('Y-m-d H:i:s T/e - U') . "\n"; + +?> +--EXPECT-- +2020-03-08 03:00:00 CDT/America/Chicago - 1583654400 +2020-03-08 03:30:00 CDT/America/Chicago - 1583656200 +2020-03-08 03:00:00 CDT/America/Chicago - 1583654400 +2020-03-08 01:59:59 CST/America/Chicago - 1583654399 -- 2.40.0