forked from zjkal/time-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeHelperTest.php
221 lines (182 loc) · 5.51 KB
/
TimeHelperTest.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
namespace zjkal\tests;
use zjkal\TimeHelper;
use PHPUnit\Framework\TestCase;
class TimeHelperTest extends TestCase
{
public function testAfterMonth()
{
$this->expectOutputString('1696132800');
print TimeHelper::afterMonth(1, '2023-9-1 12:00:00');
}
public function testSecondMinute()
{
$this->expectOutputString('3600');
print TimeHelper::secondMinute(60);
}
public function testBeforeYear()
{
$this->expectOutputString('1641009600');
print TimeHelper::beforeYear(1, '2023-1-1 12:00:00');
}
public function testAfterHour()
{
$this->expectOutputString('1693544400');
print TimeHelper::afterHour(1, '2023-9-1 12:00:00');
}
public function testSecondHour()
{
$this->expectOutputString('3600');
print TimeHelper::secondHour(1);
}
public function testSecondWeek()
{
$this->expectOutputString('604800');
print TimeHelper::secondWeek(1);
}
public function testBeforeMonth()
{
$this->expectOutputString('1669867200');
print TimeHelper::beforeMonth(1, '2023-1-1 12:00:00');
}
public function testIsThisYear()
{
$this->expectOutputString(false);
print TimeHelper::isThisYear('2022-1-1 12:00:00');
}
public function testDaysInMonth()
{
$this->expectOutputString('31');
print TimeHelper::daysInMonth('2023-1-1 12:00:00');
}
public function testBeforeWeek()
{
$this->expectOutputString('1671940800');
print TimeHelper::beforeWeek(1, '2023-1-1 12:00:00');
}
public function testBeforeDay()
{
$this->expectOutputString('1693281600');
print TimeHelper::beforeDay(3, '2023-9-1 12:00:00');
}
public function testAfterMinute()
{
$this->expectOutputString('1693541400');
print TimeHelper::afterMinute(10, '2023-9-1 12:00:00');
}
public function testAfterDay()
{
$this->expectOutputString('1693972800');
print TimeHelper::afterDay(5, '2023-9-1 12:00:00');
}
public function testIsTimestamp()
{
$this->expectOutputString(false);
print TimeHelper::isTimestamp('2023-9-1 12:00:00');
}
public function testAfterYear()
{
$this->expectOutputString('1725163200');
print TimeHelper::afterYear(1, '2023-9-1 12:00:00');
}
public function testBeforeHour()
{
$this->expectOutputString('1693537200');
print TimeHelper::beforeHour(1, '2023-9-1 12:00:00');
}
public function testIsWeekday()
{
$this->expectOutputString(true);
print TimeHelper::isWeekday('2023-9-1 12:00:00');
}
public function testFormat()
{
$this->expectOutputString('Sep 01, 2023 12:00');
print TimeHelper::format('M d, Y H:i', '2023-9-1 12:00:00');
}
public function testAfterWeek()
{
$this->expectOutputString('1694145600');
print TimeHelper::afterWeek(1, '2023-9-1 12:00:00');
}
public function testToTimestamp()
{
$this->expectOutputString('1693540800');
print TimeHelper::toTimestamp('2023-9-1 12:00:00');
}
public function testIsThisMonth()
{
$this->expectOutputString(false);
print TimeHelper::isThisMonth('2023-8-1 12:00:00');
}
public function testDiffWeeks()
{
$this->expectOutputString('1');
print TimeHelper::diffWeeks('2023-9-1 12:00:00', '2023-9-8 12:00:00');
}
public function testIsToday()
{
$this->expectOutputString(false);
print TimeHelper::isToday('2023-8-1 12:00:00');
}
public function testBeforeMinute()
{
$this->expectOutputString('1693540200');
print TimeHelper::beforeMinute(10, '2023-9-1 12:00:00');
}
public function testDaysInYear()
{
$this->expectOutputString('365');
print TimeHelper::daysInYear('2023-1-1 12:00:00');
}
public function testGetWeekDay()
{
$this->expectOutputString('5');
print TimeHelper::getWeekDay('2023-9-1 12:00:00');
}
public function testIsWeekend()
{
$this->expectOutputString(false);
print TimeHelper::isWeekend('2023-9-1 12:00:00');
}
public function testDiffYears()
{
$this->expectOutputString('2');
print TimeHelper::diffYears('2023-9-1 12:00:00', '2025-9-1 12:00:00');
}
public function testIsThisWeek()
{
$this->expectOutputString(false);
print TimeHelper::isThisWeek('2023-7-1 12:00:00');
}
public function testDiffMonths()
{
$this->expectOutputString('12');
print TimeHelper::diffMonths('2023-9-1 12:00:00', '2024-9-1 12:00:00');
}
public function testDiffDays()
{
$this->expectOutputString('366');
print TimeHelper::diffDays('2023-9-1 12:00:00', '2024-9-1 12:00:00');
}
public function testIsLeapYear()
{
$this->expectOutputString(false);
print TimeHelper::isLeapYear('2023-1-1 12:00:00');
}
public function testTimezoneFormat()
{
$this->expectOutputString('18:15:33');
print TimeHelper::timezoneFormat('Europe/London', 'America/Los_Angeles', 'Aug 15, 2023 10:15:33', 'H:i:s');
}
public function testSecondDay()
{
$this->expectOutputString('86400');
print TimeHelper::secondDay(1);
}
public function testCompare()
{
$this->expectOutputString('1');
print TimeHelper::compare('2023-9-1 12:00:00', '2023-8-1 12:00:00');
}
}