|
18 | 18 | use CodeIgniter\Test\CIUnitTestCase;
|
19 | 19 | use Config\App;
|
20 | 20 | use DateTime;
|
| 21 | +use DateTimeImmutable; |
21 | 22 | use DateTimeZone;
|
22 | 23 | use IntlDateFormatter;
|
23 | 24 | use Locale;
|
@@ -708,13 +709,28 @@ public function testSetTimezone(): void
|
708 | 709 |
|
709 | 710 | public function testSetTimestamp(): void
|
710 | 711 | {
|
711 |
| - $time = Time::parse('May 10, 2017', 'America/Chicago'); |
712 |
| - $stamp = strtotime('April 1, 2017'); |
713 |
| - $time2 = $time->setTimestamp($stamp); |
| 712 | + $time1 = Time::parse('May 10, 2017', 'America/Chicago'); |
| 713 | + |
| 714 | + $stamp = strtotime('2017-04-01'); // We use UTC as the default timezone. |
| 715 | + $time2 = $time1->setTimestamp($stamp); |
714 | 716 |
|
715 | 717 | $this->assertInstanceOf(Time::class, $time2);
|
716 |
| - $this->assertNotSame($time, $time2); |
717 |
| - $this->assertSame('2017-04-01 00:00:00', $time2->toDateTimeString()); |
| 718 | + $this->assertSame('2017-05-10 00:00:00 -05:00', $time1->format('Y-m-d H:i:s P')); |
| 719 | + $this->assertSame('2017-03-31 19:00:00 -05:00', $time2->format('Y-m-d H:i:s P')); |
| 720 | + } |
| 721 | + |
| 722 | + public function testSetTimestampDateTimeImmutable(): void |
| 723 | + { |
| 724 | + $time1 = new DateTimeImmutable( |
| 725 | + 'May 10, 2017', |
| 726 | + new DateTimeZone('America/Chicago') |
| 727 | + ); |
| 728 | + |
| 729 | + $stamp = strtotime('2017-04-01'); // We use UTC as the default timezone. |
| 730 | + $time2 = $time1->setTimestamp($stamp); |
| 731 | + |
| 732 | + $this->assertSame('2017-05-10 00:00:00 -05:00', $time1->format('Y-m-d H:i:s P')); |
| 733 | + $this->assertSame('2017-03-31 19:00:00 -05:00', $time2->format('Y-m-d H:i:s P')); |
718 | 734 | }
|
719 | 735 |
|
720 | 736 | public function testToDateString(): void
|
|
0 commit comments