/
DatetimeTest.php
60 lines (51 loc) · 1.6 KB
/
DatetimeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
namespace axios\tools\tests\unit;
use axios\tools\Datetime;
use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
class DatetimeTest extends TestCase
{
private $datetime;
protected function setUp(): void
{
parent::setUp();
$this->datetime = strtotime('2020-06-06 23:12:46');
}
public function testHourBeginEnd()
{
$obj = new Datetime($this->datetime);
list($begin, $end) = $obj->hourBeginEnd(12);
$this->assertEquals(1591444800, $begin);
$this->assertEquals(1591448399, $end);
$this->assertEquals(3599, $end - $begin);
}
public function testDayBeginEnd()
{
$obj = new Datetime($this->datetime);
list($begin, $end) = $obj->dayBeginEnd('2020-06-06');
$this->assertEquals(1591401600, $begin);
$this->assertEquals(1591487999, $end);
$this->assertEquals(86399, $end - $begin);
}
public function testMonthBeginEnd()
{
$obj = new Datetime($this->datetime);
list($begin, $end) = $obj->monthBeginEnd('2020', '6');
$this->assertEquals(1590969600, $begin);
$this->assertEquals(1593561599, $end);
$this->assertEquals(2591999, $end - $begin);
}
public function testYearBeginEnd()
{
$obj = new Datetime($this->datetime);
list($begin, $end) = $obj->yearBeginEnd('2020');
$this->assertEquals(1577836800, $begin);
$this->assertEquals(1609459199, $end);
$this->assertEquals(31622399, $end - $begin);
}
}