Skip to content

Commit d19a70c

Browse files
committed
Fix GH-9891: DateTime modify with unixtimestamp (@) must work like setTimestamp
1 parent da5cbca commit d19a70c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Apache:
66
. Fixed bug GH-9949 (Partial content on incomplete POST request). (cmb)
77

8+
- Date:
9+
. Fixed bug GH-9891 (DateTime modify with unixtimestamp (@) must work like
10+
setTimestamp). (Derick)
11+
812
- LDAP:
913
. Fixed bug GH-10112 (LDAP\Connection::__construct() refers to ldap_create()).
1014
(cmb)

ext/date/php_date.c

+4
Original file line numberDiff line numberDiff line change
@@ -2897,6 +2897,10 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{
28972897
dateobj->time->us = tmp_time->us;
28982898
}
28992899

2900+
if (tmp_time->have_zone && tmp_time->zone_type == TIMELIB_ZONETYPE_OFFSET) {
2901+
timelib_set_timezone_from_offset(dateobj->time, tmp_time->z);
2902+
}
2903+
29002904
timelib_time_dtor(tmp_time);
29012905

29022906
timelib_update_ts(dateobj->time, NULL);

ext/date/tests/gh9891.phpt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug GH-9891 (DateTime modify with unixtimestamp (@) must work like setTimestamp)
3+
--FILE--
4+
<?php
5+
$m = new DateTime('2022-12-20 14:30:25', new DateTimeZone('Europe/Paris'));
6+
$m->modify('@1234567890');
7+
var_dump($m->getTimeStamp());
8+
9+
echo "=======\n";
10+
11+
$a = new DateTime('2022-11-01 13:30:00', new DateTimezone('America/Lima'));
12+
$b = clone $a;
13+
echo '$a: ', $a->format(DateTime::ATOM), "\n";
14+
echo '$b: ', $b->format(DateTime::ATOM), "\n";
15+
echo '$a: @', $a->getTimestamp(), "\n";
16+
echo '$b: setTimestamp(', $b->getTimestamp(), ")\n";
17+
$a->modify('@' . $a->getTimestamp());
18+
$b->setTimestamp($b->getTimestamp());
19+
echo '$a: ', $a->format(DateTime::ATOM), "\n";
20+
echo '$b: ', $b->format(DateTime::ATOM), "\n";
21+
?>
22+
--EXPECT--
23+
int(1234567890)
24+
=======
25+
$a: 2022-11-01T13:30:00-05:00
26+
$b: 2022-11-01T13:30:00-05:00
27+
$a: @1667327400
28+
$b: setTimestamp(1667327400)
29+
$a: 2022-11-01T18:30:00+00:00
30+
$b: 2022-11-01T13:30:00-05:00

0 commit comments

Comments
 (0)