Skip to content

Commit d70058a

Browse files
Nate Brunettecmb69
Nate Brunette
authored andcommitted
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.
1 parent c00cce3 commit d70058a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- CURL:
1010
. Fixed bug #79199 (curl_copy_handle() memory leak). (cmb)
1111

12+
- Date:
13+
. Fixed bug #79396 (DateTime hour incorrect during DST jump forward). (Nate
14+
Brunette)
15+
1216
- SimpleXML:
1317
. Fixed bug #61597 (SXE properties may lack attributes and content). (cmb)
1418

ext/date/php_date.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,7 @@ static void php_date_time_set(zval *object, zend_long h, zend_long i, zend_long
35623562
dateobj->time->s = s;
35633563
dateobj->time->us = ms;
35643564
timelib_update_ts(dateobj->time, NULL);
3565+
timelib_update_from_sse(dateobj->time);
35653566
} /* }}} */
35663567

35673568
/* {{{ proto DateTime date_time_set(DateTime object, int hour, int minute[, int second[, int microseconds]])
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test for setting Date/Time during a forward DST transition
3+
--FILE--
4+
<?php
5+
date_default_timezone_set('America/Chicago');
6+
7+
$date = new DateTime('2020-03-08 01:30:00');
8+
echo $date->setTime(2, 0)->format('Y-m-d H:i:s T/e - U') . "\n";
9+
10+
$date = new DateTime('2020-03-08 01:30:00');
11+
echo $date->setTime(2, 30)->format('Y-m-d H:i:s T/e - U') . "\n";
12+
13+
$date = new DateTime('2020-03-08 01:30:00');
14+
echo $date->setTime(3, 0)->format('Y-m-d H:i:s T/e - U') . "\n";
15+
16+
$date = new DateTime('2020-03-08 01:30:00');
17+
echo $date->setTime(1, 59, 59)->format('Y-m-d H:i:s T/e - U') . "\n";
18+
19+
?>
20+
--EXPECT--
21+
2020-03-08 03:00:00 CDT/America/Chicago - 1583654400
22+
2020-03-08 03:30:00 CDT/America/Chicago - 1583656200
23+
2020-03-08 03:00:00 CDT/America/Chicago - 1583654400
24+
2020-03-08 01:59:59 CST/America/Chicago - 1583654399

0 commit comments

Comments
 (0)