|
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;
|
@@ -719,13 +720,28 @@ public function testSetTimezone(): void
|
719 | 720 |
|
720 | 721 | public function testSetTimestamp(): void
|
721 | 722 | {
|
722 |
| - $time = Time::parse('May 10, 2017', 'America/Chicago'); |
723 |
| - $stamp = strtotime('April 1, 2017'); |
724 |
| - $time2 = $time->setTimestamp($stamp); |
| 723 | + $time1 = Time::parse('May 10, 2017', 'America/Chicago'); |
| 724 | + |
| 725 | + $stamp = strtotime('2017-04-01'); // We use UTC as the default timezone. |
| 726 | + $time2 = $time1->setTimestamp($stamp); |
725 | 727 |
|
726 | 728 | $this->assertInstanceOf(Time::class, $time2);
|
727 |
| - $this->assertNotSame($time, $time2); |
728 |
| - $this->assertSame('2017-04-01 00:00:00', $time2->toDateTimeString()); |
| 729 | + $this->assertSame('2017-05-10 00:00:00 -05:00', $time1->format('Y-m-d H:i:s P')); |
| 730 | + $this->assertSame('2017-03-31 19:00:00 -05:00', $time2->format('Y-m-d H:i:s P')); |
| 731 | + } |
| 732 | + |
| 733 | + public function testSetTimestampDateTimeImmutable(): void |
| 734 | + { |
| 735 | + $time1 = new DateTimeImmutable( |
| 736 | + 'May 10, 2017', |
| 737 | + new DateTimeZone('America/Chicago') |
| 738 | + ); |
| 739 | + |
| 740 | + $stamp = strtotime('2017-04-01'); // We use UTC as the default timezone. |
| 741 | + $time2 = $time1->setTimestamp($stamp); |
| 742 | + |
| 743 | + $this->assertSame('2017-05-10 00:00:00 -05:00', $time1->format('Y-m-d H:i:s P')); |
| 744 | + $this->assertSame('2017-03-31 19:00:00 -05:00', $time2->format('Y-m-d H:i:s P')); |
729 | 745 | }
|
730 | 746 |
|
731 | 747 | public function testToDateString(): void
|
|
0 commit comments