/
DateTime.compare.phpt
66 lines (50 loc) · 1.34 KB
/
DateTime.compare.phpt
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
61
62
63
64
65
66
<?php declare(strict_types = 1);
/**
* Test: DateTime [comparing]
*/
require_once __DIR__ . '/../bootstrap.php';
use Contributte\Utils\DateTime;
use Tester\Assert;
// Test: datetime
test(function (): void {
// Now
$now = new DateTime('2014-1-2 00:00:00');
// Limits
$from = new DateTime('2014-1-1 00:00:00');
$until = new DateTime('2014-1-5 00:00:00');
Assert::false($from > $now);
Assert::false($until < $now);
});
// Test: datetime convert to strtotime
test(function (): void {
// Now
$now = strtotime((string) new DateTime('2014-1-2 00:00:00'));
// Limits
$from = strtotime((string) new DateTime('2014-1-1 00:00:00'));
$until = strtotime((string) new DateTime('2014-1-5 00:00:00'));
Assert::false($from > $now);
Assert::false($until < $now);
});
// Test: now == until
test(function (): void {
// Now
$now = new DateTime('2014-1-5 00:00:00');
// Limits
$from = new DateTime('2014-1-1 00:00:00');
$until = new DateTime('2014-1-5 00:00:00');
Assert::false($from > $now);
Assert::false($until < $now);
});
// Test: datetimes with DD.MM.YYYY 00:00:00
test(function (): void {
// Now
$now = new DateTime('now');
$now->setTime(0, 0, 0);
// Limits
$from = new DateTime('- 1 day');
$from->setTime(0, 0, 0);
$until = new DateTime('now');
$until->setTime(0, 0, 0);
Assert::false($from > $now);
Assert::false($until < $now);
});