xref: /PHP-8.1/ext/date/tests/gh9866.phpt (revision d0218511)
1--TEST--
2Bug GH-9866 (Time zone bug with \DateTimeInterface::diff())
3--FILE--
4<?php
5function 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);
16var_dump($result);
17$diff = $start->diff($end);
18echo $diff->format("%R %Y %M %D (%a) %H %I %S %F"), "\n";
19?>
20--EXPECT--
21int(21)
22+ 21 07 04 (7886) 23 30 37 092394
23