Skip to content

Commit d021851

Browse files
committed
Fixed GH-9699, GH-9866, and GH-9880 (problems with diff); and GH-9700 (greedy tzid parsing)
1 parent 818b46a commit d021851

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

NEWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ PHP NEWS
1010
. Fixed bug GH-9650 (Can't initialize heap: [0x000001e7]). (Michael Voříšek)
1111
. Fixed potentially undefined behavior in Windows ftok(3) emulation. (cmb)
1212

13+
- Date:
14+
. Fixed bug GH-9699 (DateTimeImmutable::diff differences in 8.1.10 onwards -
15+
timezone related). (Derick)
16+
. Fixed bug GH-9700 (DateTime::createFromFormat: Parsing TZID string is too
17+
greedy). (Derick)
18+
. Fixed bug GH-9866 (Time zone bug with \DateTimeInterface::diff()). (Derick)
19+
. Fixed bug GH-9880 (DateTime diff returns wrong sign on day count when using
20+
a timezone). (Derick)
21+
1322
- FPM:
1423
. Fixed bug GH-9959 (Solaris port event mechanism is still broken after bug
1524
#66694). (Petr Sumbera)

ext/date/tests/gh9699.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug GH-9699 (DateTimeImmutable::diff differences in 8.1.10 onwards - timezone related)
3+
--FILE--
4+
<?php
5+
6+
$date = new DateTimeImmutable('2022-10-09 02:41:54.515330', new DateTimeZone('America/Los_Angeles'));
7+
$now = new DateTimeImmutable('2022-10-10 08:41:54.534620', new DateTimeZone('UTC'));
8+
9+
echo $date->diff($now)->format("%R %Y %M %D %H %I %S %F"), "\n";
10+
?>
11+
--EXPECT--
12+
+ 00 00 00 23 00 00 019290

ext/date/tests/gh9700.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug GH-9700 (DateTime::createFromFormat: Parsing TZID string is too greedy)
3+
--FILE--
4+
<?php
5+
var_dump(DateTime::createFromFormat('Y-m-d\TH:i:sP[e]', '2022-02-18T00:00:00+01:00[Europe/Berlin]'));
6+
?>
7+
--EXPECTF--
8+
object(DateTime)#%d (%d) {
9+
["date"]=>
10+
string(26) "2022-02-18 00:00:00.000000"
11+
["timezone_type"]=>
12+
int(3)
13+
["timezone"]=>
14+
string(13) "Europe/Berlin"
15+
}

ext/date/tests/gh9866.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug GH-9866 (Time zone bug with \DateTimeInterface::diff())
3+
--FILE--
4+
<?php
5+
function getYearsBetween(
6+
\DateTimeImmutable $startDate,
7+
\DateTimeImmutable $endDate,
8+
): int {
9+
$dateInterval = $startDate->diff($endDate, true);
10+
return $dateInterval->y;
11+
}
12+
13+
$start = new \DateTimeImmutable('2000-11-01 09:29:22.907606', new \DateTimeZone('America/Chicago'));
14+
$end = new \DateTimeImmutable('2022-06-06 11:00:00.000000', new \DateTimeZone('America/New_York'));
15+
$result = getYearsBetween($start, $end);
16+
var_dump($result);
17+
$diff = $start->diff($end);
18+
echo $diff->format("%R %Y %M %D (%a) %H %I %S %F"), "\n";
19+
?>
20+
--EXPECT--
21+
int(21)
22+
+ 21 07 04 (7886) 23 30 37 092394

ext/date/tests/gh9880.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug GH-9880 (DateTime diff returns wrong sign on day count when using a timezone)
3+
--FILE--
4+
<?php
5+
6+
ini_set('date.timezone', 'America/Los_Angeles');
7+
8+
$nowTime = new DateTime();
9+
$nowTime->setTimestamp(1667416695);
10+
11+
$dateTime = new DateTime();
12+
$dateTime->setTimestamp(1671904800);
13+
$dateTime->setTimezone(new DateTimeZone('America/New_York'));
14+
15+
echo $dateTime->diff($nowTime)->format('%R %a %H %I %S'), "\n";
16+
?>
17+
--EXPECT--
18+
- 51 22 41 45

0 commit comments

Comments
 (0)