Skip to content

Commit b346956

Browse files
author
Lonny Kapelushnik
committed
Fix bugs 62561,62896 (Modifying DateTime::__construct,date_create adds an hour)
Prevent a unix timestamp, which is always GMT when being parsed, from taking on the local timezones DST flag.
1 parent 34c3985 commit b346956

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

ext/date/lib/parse_date.re

+2
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
10731073
s->time->is_localtime = 1;
10741074
s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
10751075
s->time->z = 0;
1076+
s->time->dst = 0;
10761077

10771078
TIMELIB_DEINIT;
10781079
return TIMELIB_RELATIVE;
@@ -2077,6 +2078,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
20772078
s->time->is_localtime = 1;
20782079
s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
20792080
s->time->z = 0;
2081+
s->time->dst = 0;
20802082
break;
20812083

20822084
case 'e': /* timezone */

ext/date/tests/bug62561.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #62561 Unixtimestamp may take on local times DST flag (this test will only be valid during EDT)
3+
--FILE--
4+
<?php
5+
$tz = new DateTimeZone('America/New_York');
6+
$ts = new DateTime('@1341115200', $tz);
7+
$int = new DateInterval('P1D');
8+
$dayFromTs = new DateTime('@1341115200', new DateTimeZone('America/New_York'));
9+
$dayFromTs->add($int);
10+
11+
echo 'ts: '.$ts->format('Y-m-d H:i:s')."\n";
12+
echo 'day from ts: '.$dayFromTs->format('Y-m-d H:i:s')."\n";
13+
?>
14+
--EXPECT--
15+
ts: 2012-07-01 04:00:00
16+
day from ts: 2012-07-02 04:00:00

ext/date/tests/bug62896.phpt

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #62896 Unixtimestamp may take on local times DST flag (this test will only be valid during CEST)
3+
--FILE--
4+
<?php
5+
$tz = new DateTimeZone('Europe/Berlin');
6+
7+
echo "FROM TIMESTAMP, NO TZ:\n";
8+
9+
$date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));
10+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
11+
12+
$date->modify('+0 days');
13+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
14+
15+
echo "FROM TIMESTAMP, WITH TZ:\n";
16+
17+
$date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));
18+
$date->setTimezone($tz);
19+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
20+
21+
$date->modify('+0 days');
22+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
23+
24+
echo "FROM STRING:\n";
25+
26+
$date = new DateTime('2012-08-22 00:00:00 CEST', $tz);
27+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
28+
29+
$date->modify('+0 days');
30+
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
31+
--EXPECT--
32+
FROM TIMESTAMP, NO TZ:
33+
2012-08-21 22:00:00 GMT+0000 (offset 0)
34+
2012-08-21 22:00:00 GMT+0000 (offset 0)
35+
FROM TIMESTAMP, WITH TZ:
36+
2012-08-22 00:00:00 CEST (offset 7200)
37+
2012-08-22 00:00:00 CEST (offset 7200)
38+
FROM STRING:
39+
2012-08-22 00:00:00 CEST (offset 7200)
40+
2012-08-22 00:00:00 CEST (offset 7200)

0 commit comments

Comments
 (0)