-
Notifications
You must be signed in to change notification settings - Fork 24
/
HoursHelperTest.php
241 lines (193 loc) · 6.06 KB
/
HoursHelperTest.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
namespace Label84\HoursHelper\Tests;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Label84\HoursHelper\Facades\HoursHelper;
class HoursHelperTest extends TestCase
{
public function test_it_can_have_the_start_and_end_value_in_string_format()
{
$result = HoursHelper::create('08:00', '09:00', 15);
$collection = new Collection([
'08:00',
'08:15',
'08:30',
'08:45',
'09:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_have_the_start_and_end_value_in_datetime_format()
{
$start = Carbon::createFromFormat('H:i', '08:00');
$end = Carbon::createFromFormat('H:i', '09:00');
$result = HoursHelper::create($start, $end, 15);
$collection = new Collection([
'08:00',
'08:15',
'08:30',
'08:45',
'09:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_have_an_end_time_later_than_midnight()
{
$result = HoursHelper::create('23:45', '00:15', 15);
$collection = new Collection([
'23:45',
'00:00',
'00:15',
]);
$this->assertEquals($collection, $result);
}
public function test_it_uses_the_h_i_formatter_by_default()
{
$result = HoursHelper::create('08:00', '08:30', 30, 'H:i');
$collection = new Collection([
'08:00',
'08:30',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_have_dates_in_the_formatter()
{
$result = HoursHelper::create('2022-01-01 08:00', '2022-01-01 08:30', 15, 'Y-m-d H:i');
$collection = new Collection([
'2022-01-01 08:00',
'2022-01-01 08:15',
'2022-01-01 08:30',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_have_the_12_hour_format_in_the_formatter()
{
$result = HoursHelper::create('11:00', '13:00', 60, 'g:i A');
$collection = new Collection([
'11:00 AM',
'12:00 PM',
'1:00 PM',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_have_an_interval_of_multiple_days()
{
$result = HoursHelper::create('2022-01-01', '2022-01-04', 60 * 24 * 1.5, 'Y-m-d H:i');
$collection = new Collection([
'2022-01-01 00:00',
'2022-01-02 12:00',
'2022-01-04 00:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_times()
{
$result = HoursHelper::create('08:30', '10:00', 15, 'H:i', [
['09:00', '09:30'],
]);
$collection = new Collection([
'08:30',
'08:45',
'09:45',
'10:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_dates()
{
$result = HoursHelper::create('2021-01-01 23:30', '2021-01-03 00:30', 15, 'Y-m-d H:i', [
['2021-01-02 00:00', '2021-01-02 23:59'],
]);
$collection = new Collection([
'2021-01-01 23:30',
'2021-01-01 23:45',
'2021-01-03 00:00',
'2021-01-03 00:15',
'2021-01-03 00:30',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_multiple_time_intervals()
{
$result = HoursHelper::create('08:00', '13:00', 60, 'H:i', [
['09:00', '09:59'],
['11:00', '11:59'],
]);
$collection = new Collection([
'08:00',
'10:00',
'12:00',
'13:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_time_interval_that_is_past_midnight()
{
$result = HoursHelper::create('22:00', '03:00', 60, 'H:i', [
['01:00', '02:00'],
]);
$collection = new Collection([
'22:00',
'23:00',
'00:00',
'03:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_time_intervals_that_are_before_midnight_and_past_midnight()
{
$result = HoursHelper::create('18:00', '05:00', 60, 'H:i', [
['21:00', '23:00'],
['01:00', '02:00'],
]);
$collection = new Collection([
'18:00',
'19:00',
'20:00',
'00:00',
'03:00',
'04:00',
'05:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_time_interval_including_midnight()
{
$result = HoursHelper::create('23:00', '00:30', 15, 'H:i', [
['23:45', '00:14'],
]);
$collection = new Collection([
'23:00',
'23:15',
'23:30',
'00:15',
'00:30',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_dates_that_are_during_midnight()
{
$result = HoursHelper::create('2021-01-01 23:30', '2021-01-03 01:00', 15, 'Y-m-d H:i', [
['2021-01-01 23:45', '2021-01-03 00:30'],
]);
$collection = new Collection([
'2021-01-01 23:30',
'2021-01-03 00:45',
'2021-01-03 01:00',
]);
$this->assertEquals($collection, $result);
}
public function test_it_can_exclude_dates_that_are_on_midnight()
{
$result = HoursHelper::create('2023-12-19 23:30', '2023-12-21 01:00', 15, 'Y-m-d H:i', [
['2023-12-20 00:00', '2023-12-21 00:30'],
]);
$collection = new Collection([
'2023-12-19 23:30',
'2023-12-19 23:45',
'2023-12-21 00:45',
'2023-12-21 01:00',
]);
$this->assertEquals($collection, $result);
}
}