Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
CRAP | |
100.00% |
1 / 1 |
Util | |
100.00% |
9 / 9 |
|
100.00% |
9 / 9 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isFeature | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPast | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
eq | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
ne | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
gt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
ge | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
le | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
lt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2023 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen\DateTime; |
10 | |
11 | use DateTimeInterface; |
12 | |
13 | /** |
14 | * \DateTimeクラスに関するUtilを提供するクラス |
15 | */ |
16 | class Util |
17 | { |
18 | private DateTimeInterface $dateTime; |
19 | |
20 | public function __construct(DateTimeInterface $dateTime) |
21 | { |
22 | $this->dateTime = $dateTime; |
23 | } |
24 | |
25 | /** |
26 | * 日付が未来かどうか確認します |
27 | * |
28 | * @return bool 未来の場合はtrueを、それ以外の場合はfalseを返します |
29 | */ |
30 | public function isFeature(): bool |
31 | { |
32 | return \time() < $this->dateTime->getTimestamp(); |
33 | } |
34 | |
35 | /** |
36 | * 日付が過去かどうか確認します |
37 | * |
38 | * @return bool 過去の場合はtrueを、それ以外の場合はfalseを返します |
39 | */ |
40 | public function isPast(): bool |
41 | { |
42 | return $this->dateTime->getTimestamp() < \time(); |
43 | } |
44 | |
45 | /** |
46 | * 自身の日付情報と入力の日付情報が同じか確認します |
47 | * |
48 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
49 | * |
50 | * @return bool 同じ場合はtrueを、それ以外の場合はfalseを返します |
51 | */ |
52 | public function eq(DateTimeInterface $dateTime): bool |
53 | { |
54 | return $this->dateTime->getTimestamp() === $dateTime->getTimestamp(); |
55 | } |
56 | |
57 | /** |
58 | * 自身の日付情報と入力の日付情報が異なるか確認します |
59 | * |
60 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
61 | * |
62 | * @return bool 異なる場合はtrueを、それ以外の場合はfalseを返します |
63 | */ |
64 | public function ne(DateTimeInterface $dateTime): bool |
65 | { |
66 | return $this->dateTime->getTimestamp() !== $dateTime->getTimestamp(); |
67 | } |
68 | |
69 | /** |
70 | * 自身の日付が入力日付より大きい確認します($this > $dateTime) |
71 | * |
72 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
73 | * |
74 | * @return bool 大きい場合はtrueを、それ以外の場合はfalseを返します |
75 | */ |
76 | public function gt(DateTimeInterface $dateTime): bool |
77 | { |
78 | return $this->dateTime->getTimestamp() > $dateTime->getTimestamp(); |
79 | } |
80 | |
81 | /** |
82 | * 自身の日付が入力日付以上か確認します($this >= $dateTime) |
83 | * |
84 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
85 | * |
86 | * @return bool 以上の場合はtrueを、それ以外の場合はfalseを返します |
87 | */ |
88 | public function ge(DateTimeInterface $dateTime): bool |
89 | { |
90 | return $this->dateTime->getTimestamp() >= $dateTime->getTimestamp(); |
91 | } |
92 | |
93 | /** |
94 | * 自身の日付が入力日付以下か確認します($this <= $dateTime) |
95 | * |
96 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
97 | * |
98 | * @return bool 以下の場合はtrueを、それ以外の場合はfalseを返します |
99 | */ |
100 | public function le(DateTimeInterface $dateTime): bool |
101 | { |
102 | return $this->dateTime->getTimestamp() <= $dateTime->getTimestamp(); |
103 | } |
104 | |
105 | /** |
106 | * 自身の日付が入力日付より小さいか確認します($this < $dateTime) |
107 | * |
108 | * @param DateTimeInterface $dateTime 比較対象の日付情報を渡します |
109 | * |
110 | * @return bool 小さい場合はtrueを、それ以外の場合はfalseを返します |
111 | */ |
112 | public function lt(DateTimeInterface $dateTime): bool |
113 | { |
114 | return $this->dateTime->getTimestamp() < $dateTime->getTimestamp(); |
115 | } |
116 | } |