56 lines
2.6 KiB
PHP
56 lines
2.6 KiB
PHP
<?php
|
|
namespace nur\b\date;
|
|
|
|
use nur\t\TestCase;
|
|
|
|
class TimeTest extends TestCase {
|
|
function testGetc() {
|
|
self::assertSame(0, (new Time(0))->getu());
|
|
self::assertSame(86399, (new Time(-1))->getu());
|
|
self::assertSame(1, (new Time(1))->getu());
|
|
self::assertSame(120, (new Time(120))->getu());
|
|
self::assertSame(86400, (new Time(86400))->getu());
|
|
self::assertSame(0, (new Time(-86400))->getu());
|
|
}
|
|
|
|
function testAddc() {
|
|
$t1 = new Time(0);
|
|
$t2 = $t1->addu(0); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(10); self::assertNotSame($t2, $t1); self::assertSame(10, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(10); self::assertNotSame($t2, $t1); self::assertSame(20, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(100); self::assertNotSame($t2, $t1); self::assertSame(120, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(86280); self::assertNotSame($t2, $t1); self::assertSame(86400, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(86400); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->addu(-86400); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
}
|
|
|
|
function testSubc() {
|
|
$t1 = new Time(0);
|
|
$t2 = $t1->subu(-86400); self::assertNotSame($t2, $t1); self::assertSame(86400, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->subu(86400); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
$t1 = new Time(120);
|
|
$t2 = $t1->subu(100); self::assertNotSame($t2, $t1); self::assertSame(20, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->subu(10); self::assertNotSame($t2, $t1); self::assertSame(10, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->subu(10); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
$t2 = $t1->subu(0); self::assertNotSame($t2, $t1); self::assertSame(0, $t2->getu()); $t1 = $t2;
|
|
}
|
|
|
|
function test__toString() {
|
|
self::assertSame("00:00:00", strval(new Time(0)));
|
|
self::assertSame("00:00:56", strval(new Time(56)));
|
|
self::assertSame("00:02:00", strval(new Time(120)));
|
|
self::assertSame("23:59:59", strval(new Time(86399)));
|
|
self::assertSame("24:00:00", strval(new Time(86400)));
|
|
self::assertSame("00:00:01", strval(new Time(86401)));
|
|
}
|
|
|
|
function testFormat() {
|
|
self::assertSame("00:00:00", (new Time(0))->format());
|
|
self::assertSame("00:00:56", (new Time(56))->format());
|
|
self::assertSame("00:02:00", (new Time(120))->format());
|
|
self::assertSame("23:59:59", (new Time(86399))->format());
|
|
self::assertSame("24:00:00", (new Time(86400))->format());
|
|
self::assertSame("00:00:01", (new Time(86401))->format());
|
|
}
|
|
}
|