32 lines
895 B
PHP
32 lines
895 B
PHP
<?php
|
|
namespace nur\sery\php\time;
|
|
|
|
use DateTimeZone;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class DateTest extends TestCase {
|
|
protected static function dt(string $datetime): Date {
|
|
return new Date($datetime, new DateTimeZone("Indian/Reunion"));
|
|
}
|
|
|
|
function testDate() {
|
|
$date = self::dt("2024-04-05 09:15:23");
|
|
|
|
self::assertEquals("05/04/2024", $date->format());
|
|
self::assertEquals("05/04/2024", strval($date));
|
|
self::assertEquals("2024", $date->year);
|
|
self::assertEquals("04", $date->month);
|
|
self::assertEquals("05", $date->day);
|
|
self::assertEquals("00", $date->hour);
|
|
self::assertEquals("00", $date->minute);
|
|
self::assertEquals("00", $date->second);
|
|
self::assertEquals("+04:00", $date->timezone);
|
|
}
|
|
|
|
function testClone() {
|
|
$date = self::dt("now");
|
|
$clone = Date::clone($date);
|
|
self::assertInstanceOf(DateTime::class, $clone);
|
|
}
|
|
}
|