|
| 1 | +<?php |
| 2 | +use MaplePHP\DTO\Format\Clock; |
| 3 | +use MaplePHP\DTO\Traverse; |
| 4 | +use MaplePHP\Unitary\{Config\TestConfig, Expect, TestCase}; |
| 5 | + |
| 6 | +$config = TestConfig::make("Testing clock iso")->withName("clock-iso"); |
| 7 | + |
| 8 | +group($config, function(TestCase $case) { |
| 9 | + |
| 10 | + Clock::setDefaultTimezone('Europe/Stockholm'); |
| 11 | + |
| 12 | + $clockObj = Traverse::value([ |
| 13 | + "summer" => "2025-06-03T12:30:00Z", |
| 14 | + "winter" => "2025-01-03T12:30:00Z", |
| 15 | + "localA" => "2025-06-03T12:30:00", |
| 16 | + "localB" => "2025-06-03T12:30:00+02:00", |
| 17 | + ]); |
| 18 | + |
| 19 | + $case->expect($clockObj->summer->clock()->format('y/m/d \k\l. H:i:s')) |
| 20 | + ->isEqualTo("25/06/03 kl. 14:30:00") |
| 21 | + ->assert("Z-timestamp should be parsed as UTC and converted to Europe/Stockholm (summer time)."); |
| 22 | + |
| 23 | + $case->expect($clockObj->winter->clock()->format('y/m/d \k\l. H:i:s')) |
| 24 | + ->isEqualTo("25/01/03 kl. 13:30:00") |
| 25 | + ->assert("Z-timestamp should be parsed as UTC and converted to Europe/Stockholm (winter time)."); |
| 26 | + |
| 27 | + $case->expect($clockObj->localA->clock()->format('y/m/d \k\l. H:i:s')) |
| 28 | + ->isEqualTo("25/06/03 kl. 12:30:00") |
| 29 | + ->assert("Offset-less ISO 8601 datetime should be treated as local time in Europe/Stockholm."); |
| 30 | + |
| 31 | + $case->expect($clockObj->localB->clock()->format('y/m/d \k\l. H:i:s')) |
| 32 | + ->isEqualTo("25/06/03 kl. 12:30:00") |
| 33 | + ->assert("Datetime with +02:00 offset should align with local Europe/Stockholm time without shifting wall time."); |
| 34 | + |
| 35 | +}); |
0 commit comments