|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
|
4
|
|
|
* Date: 9/22/14 |
|
5
|
|
|
* Time: 12:31 AM |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Tests\NilPortugues\Validator\Validation\DateTime; |
|
12
|
|
|
|
|
13
|
|
|
use NilPortugues\Validator\Validation\DateTime\DateTimeValidation; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class DateTimeValidatorTest |
|
17
|
|
|
* @package Tests\NilPortugues\Validator\Validation\DateTimeAttribute |
|
18
|
|
|
*/ |
|
19
|
|
|
class DateTimeValidatorTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
*/ |
|
24
|
|
|
public function itShouldCheckIfDate() |
|
25
|
|
|
{ |
|
26
|
|
|
$date1 = '2012-01-01 00:00:00'; |
|
27
|
|
|
$date2 = new \DateTime($date1); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertTrue(DateTimeValidation::isDateTime($date1)); |
|
30
|
|
|
$this->assertTrue(DateTimeValidation::isDateTime($date2)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @test |
|
35
|
|
|
*/ |
|
36
|
|
|
public function itShouldCheckIfDateIsBefore() |
|
37
|
|
|
{ |
|
38
|
|
|
$date1 = '2012-01-01 00:00:00'; |
|
39
|
|
|
$date2 = new \DateTime($date1); |
|
40
|
|
|
|
|
41
|
|
|
$limit1 = '2013-12-31 23:59:59'; |
|
42
|
|
|
|
|
43
|
|
|
$this->assertTrue(DateTimeValidation::isBefore($date1, $limit1, false)); |
|
44
|
|
|
$this->assertTrue(DateTimeValidation::isBefore($date2, $limit1, false)); |
|
45
|
|
|
|
|
46
|
|
|
$this->assertTrue(DateTimeValidation::isBefore($date1, $date1, true)); |
|
47
|
|
|
$this->assertTrue(DateTimeValidation::isBefore($date2, $date2, true)); |
|
48
|
|
|
|
|
49
|
|
|
$limit2 = '2010-01-01 00:00:00'; |
|
50
|
|
|
|
|
51
|
|
|
$this->assertFalse(DateTimeValidation::isBefore($date1, $limit2)); |
|
52
|
|
|
$this->assertFalse(DateTimeValidation::isBefore($date2, $limit2)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function itShouldCheckIfDateIsAfter() |
|
59
|
|
|
{ |
|
60
|
|
|
$date1 = '2014-01-01 00:00:00'; |
|
61
|
|
|
$date2 = new \DateTime($date1); |
|
62
|
|
|
|
|
63
|
|
|
$limit1 = '2013-12-31 23:59:59'; |
|
64
|
|
|
|
|
65
|
|
|
$this->assertTrue(DateTimeValidation::isAfter($date1, $limit1, false)); |
|
66
|
|
|
$this->assertTrue(DateTimeValidation::isAfter($date2, $limit1, false)); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertTrue(DateTimeValidation::isAfter($date1, $date1, true)); |
|
69
|
|
|
$this->assertTrue(DateTimeValidation::isAfter($date2, $date2, true)); |
|
70
|
|
|
|
|
71
|
|
|
$limit2 = '2015-01-01 00:00:00'; |
|
72
|
|
|
|
|
73
|
|
|
$this->assertFalse(DateTimeValidation::isAfter($date1, $limit2)); |
|
74
|
|
|
$this->assertFalse(DateTimeValidation::isAfter($date2, $limit2)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @test |
|
79
|
|
|
*/ |
|
80
|
|
|
public function itShouldCheckIfDateIsBetween() |
|
81
|
|
|
{ |
|
82
|
|
|
$date1 = '2014-01-01 00:00:00'; |
|
83
|
|
|
$date2 = new \DateTime($date1); |
|
84
|
|
|
|
|
85
|
|
|
$minDate = '2013-01-01 00:00:00'; |
|
86
|
|
|
$maxDate = '2015-01-01 00:00:00'; |
|
87
|
|
|
|
|
88
|
|
|
$this->assertTrue(DateTimeValidation::isBetween($date1, $minDate, $maxDate, false)); |
|
89
|
|
|
$this->assertTrue(DateTimeValidation::isBetween($date2, $minDate, $maxDate, false)); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertTrue(DateTimeValidation::isBetween($date1, $minDate, $maxDate, true)); |
|
92
|
|
|
$this->assertTrue(DateTimeValidation::isBetween($date2, $minDate, $maxDate, true)); |
|
93
|
|
|
|
|
94
|
|
|
$minDate = '2013-12-01 00:00:00'; |
|
95
|
|
|
$maxDate = '2013-12-30 00:00:00'; |
|
96
|
|
|
|
|
97
|
|
|
$this->assertFalse(DateTimeValidation::isBetween($date1, $minDate, $maxDate, false)); |
|
98
|
|
|
$this->assertFalse(DateTimeValidation::isBetween($date1, $minDate, $maxDate, true)); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @test |
|
103
|
|
|
*/ |
|
104
|
|
|
public function itShouldCheckIfIsMonday() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertTrue(DateTimeValidation::isMonday('2014-09-22')); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @test |
|
111
|
|
|
*/ |
|
112
|
|
|
public function itShouldCheckIfIsTuesday() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->assertTrue(DateTimeValidation::isTuesday('2014-09-23')); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @test |
|
119
|
|
|
*/ |
|
120
|
|
|
public function itShouldCheckIfIsWednesday() |
|
121
|
|
|
{ |
|
122
|
|
|
$this->assertTrue(DateTimeValidation::isWednesday('2014-09-24')); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @test |
|
127
|
|
|
*/ |
|
128
|
|
|
public function itShouldCheckIfIsThursday() |
|
129
|
|
|
{ |
|
130
|
|
|
$this->assertTrue(DateTimeValidation::isThursday('2014-09-25')); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @test |
|
135
|
|
|
*/ |
|
136
|
|
|
public function itShouldCheckIfIsFriday() |
|
137
|
|
|
{ |
|
138
|
|
|
$this->assertTrue(DateTimeValidation::isFriday('2014-09-26')); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @test |
|
143
|
|
|
*/ |
|
144
|
|
|
public function itShouldCheckIfIsSaturday() |
|
145
|
|
|
{ |
|
146
|
|
|
$this->assertTrue(DateTimeValidation::isSaturday('2014-09-27')); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @test |
|
151
|
|
|
*/ |
|
152
|
|
|
public function itShouldCheckIfIsSunday() |
|
153
|
|
|
{ |
|
154
|
|
|
$this->assertTrue(DateTimeValidation::isSunday('2014-09-28')); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @test |
|
159
|
|
|
*/ |
|
160
|
|
|
public function itShouldCheckIfIsToday() |
|
161
|
|
|
{ |
|
162
|
|
|
$date = new \DateTime('now'); |
|
163
|
|
|
|
|
164
|
|
|
$this->assertTrue(DateTimeValidation::isToday($date)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @test |
|
169
|
|
|
*/ |
|
170
|
|
|
public function itShouldCheckIfIsYesterday() |
|
171
|
|
|
{ |
|
172
|
|
|
$date = new \DateTime('now -1 day'); |
|
173
|
|
|
|
|
174
|
|
|
$this->assertTrue(DateTimeValidation::isYesterday($date)); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @test |
|
179
|
|
|
*/ |
|
180
|
|
|
public function itShouldCheckIfIsTomorrow() |
|
181
|
|
|
{ |
|
182
|
|
|
$date = new \DateTime('now +1 day'); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertTrue(DateTimeValidation::isTomorrow($date)); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @test |
|
189
|
|
|
*/ |
|
190
|
|
|
public function itShouldCheckIfIsLeapYear() |
|
191
|
|
|
{ |
|
192
|
|
|
$date = new \DateTime('2016-01-01'); |
|
193
|
|
|
|
|
194
|
|
|
$this->assertTrue(DateTimeValidation::isLeapYear($date)); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @test |
|
199
|
|
|
*/ |
|
200
|
|
|
public function itShouldCheckIfIsWeekend() |
|
201
|
|
|
{ |
|
202
|
|
|
$this->assertTrue(DateTimeValidation::isWeekend('2014-09-20')); |
|
203
|
|
|
$this->assertFalse(DateTimeValidation::isWeekend('2014-09-22')); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @test |
|
208
|
|
|
*/ |
|
209
|
|
|
public function itShouldCheckIfIsWeekday() |
|
210
|
|
|
{ |
|
211
|
|
|
$this->assertFalse(DateTimeValidation::isWeekday('2014-09-20')); |
|
212
|
|
|
$this->assertTrue(DateTimeValidation::isWeekday('2014-09-22')); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
/** |
|
216
|
|
|
* @test |
|
217
|
|
|
*/ |
|
218
|
|
|
public function itShouldCheckIfIsMorning() |
|
219
|
|
|
{ |
|
220
|
|
|
$this->assertTrue(DateTimeValidation::isMorning('07:20:15')); |
|
221
|
|
|
$this->assertFalse(DateTimeValidation::isMorning('20:15:00')); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @test |
|
226
|
|
|
*/ |
|
227
|
|
|
public function itShouldCheckIfIsAfternoon() |
|
228
|
|
|
{ |
|
229
|
|
|
$this->assertTrue(DateTimeValidation::isAftenoon('12:00:00')); |
|
230
|
|
|
$this->assertFalse(DateTimeValidation::isAftenoon('20:15:00')); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @test |
|
235
|
|
|
*/ |
|
236
|
|
|
public function itShouldCheckIfIsEvening() |
|
237
|
|
|
{ |
|
238
|
|
|
$this->assertTrue(DateTimeValidation::isEvening('18:00:00')); |
|
239
|
|
|
$this->assertFalse(DateTimeValidation::isEvening('07:15:00')); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @test |
|
244
|
|
|
*/ |
|
245
|
|
|
public function itShouldCheckIfIsNight() |
|
246
|
|
|
{ |
|
247
|
|
|
$this->assertTrue(DateTimeValidation::isNight('01:00:00')); |
|
248
|
|
|
$this->assertFalse(DateTimeValidation::isNight('12:15:00')); |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
|