nur-sery/tests/php/time/DateTimeTest.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2024-04-06 05:36:48 +04:00
<?php
namespace nur\sery\php\time;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
class DateTimeTest extends TestCase {
protected static function dt(string $datetime): DateTime {
return new DateTime($datetime, new DateTimeZone("Indian/Reunion"));
}
function testDateTime() {
$date = self::dt("2024-04-05 09:15:23");
self::assertEquals("05/04/2024 09:15:23", $date->format());
self::assertEquals("05/04/2024 09:15:23", strval($date));
2024-04-06 06:05:48 +04:00
self::assertSame(2024, $date->year);
self::assertSame(4, $date->month);
self::assertSame(5, $date->day);
self::assertSame(9, $date->hour);
self::assertSame(15, $date->minute);
self::assertSame(23, $date->second);
self::assertSame(5, $date->wday);
self::assertSame(14, $date->wnum);
2024-04-06 05:36:48 +04:00
self::assertEquals("+04:00", $date->timezone);
2024-04-06 06:05:48 +04:00
self::assertSame("05/04/2024 09:15:23", $date->datetime);
self::assertSame("05/04/2024", $date->date);
2024-04-06 05:36:48 +04:00
}
function testClone() {
$date = self::dt("now");
$clone = DateTime::clone($date);
self::assertInstanceOf(DateTime::class, $clone);
}
}