|
| 1 | +--TEST-- |
| 2 | +Bug GH-21616 (DateTime::modify() does not respect DST transitions) |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | +/* Spring forward: Europe/London, 2025-03-30 01:00 GMT -> 02:00 BST */ |
| 6 | +$tz = new DateTimeZone('Europe/London'); |
| 7 | + |
| 8 | +/* +1s then -1s must round-trip */ |
| 9 | +$dt = new DateTime('2025-03-30 00:59:59', $tz); |
| 10 | +$dt->modify('+1 second'); |
| 11 | +$dt->modify('-1 second'); |
| 12 | +echo $dt->format('Y-m-d H:i:s T U'), "\n"; |
| 13 | + |
| 14 | +/* -1s from 02:00 BST must land at 00:59:59 GMT, not 02:59:59 BST */ |
| 15 | +$dt2 = new DateTime('2025-03-30 02:00:00', $tz); |
| 16 | +echo $dt2->modify('-1 second')->format('Y-m-d H:i:s T U'), "\n"; |
| 17 | + |
| 18 | +/* month + hours: +1 month lands before the DST boundary, so +1 hour is plain GMT */ |
| 19 | +$dt3 = new DateTime('2025-02-28 00:30:00', $tz); |
| 20 | +echo $dt3->modify('+1 month +1 hour')->format('Y-m-d H:i:s T U'), "\n"; |
| 21 | + |
| 22 | +/* first/last day of must still work */ |
| 23 | +$base = new DateTimeImmutable('2025-03-15 10:00:00', $tz); |
| 24 | +echo $base->modify('first day of next month')->format('Y-m-d H:i:s T'), "\n"; |
| 25 | +echo $base->modify('last day of this month')->format('Y-m-d H:i:s T'), "\n"; |
| 26 | + |
| 27 | +/* +61 minutes from just before the gap -- minutes must also count as elapsed time */ |
| 28 | +$dt4 = new DateTime('2025-03-30 00:59:00', $tz); |
| 29 | +echo $dt4->modify('+61 minutes')->format('Y-m-d H:i:s T U'), "\n"; |
| 30 | + |
| 31 | +/* DateTimeImmutable must behave the same as mutable DateTime */ |
| 32 | +$dt5 = new DateTimeImmutable('2025-03-30 02:00:00', $tz); |
| 33 | +echo $dt5->modify('-1 second')->format('Y-m-d H:i:s T U'), "\n"; |
| 34 | +?> |
| 35 | +--EXPECT-- |
| 36 | +2025-03-30 00:59:59 GMT 1743296399 |
| 37 | +2025-03-30 00:59:59 GMT 1743296399 |
| 38 | +2025-03-28 01:30:00 GMT 1743125400 |
| 39 | +2025-04-01 10:00:00 BST |
| 40 | +2025-03-31 10:00:00 BST |
| 41 | +2025-03-30 03:00:00 BST 1743300000 |
| 42 | +2025-03-30 00:59:59 GMT 1743296399 |
0 commit comments