-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.php
More file actions
827 lines (727 loc) · 21.3 KB
/
Copy pathDate.php
File metadata and controls
827 lines (727 loc) · 21.3 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
<?php namespace Codeception\Module;
use Codeception\Module;
use Carbon\Carbon;
class Date extends Module
{
/* ----------------- Days ----------------- */
/**
* See date is today's date.
*
* @param string $date
*/
public function seeDateIsToday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isToday());
}
/**
* See date is not today's date.
*
* @param string $date
*/
public function dontSeeDateIsToday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isToday());
}
/**
* See date is tomorrows date.
*
* @param string $date
*/
public function seeDateIsTomorrow($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isTomorrow());
}
/**
* See date is not tomorrows date.
*
* @param string $date
*/
public function dontSeeDateIsTomorrow($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isTomorrow());
}
/**
* See date was yesterdays date.
*
* @param string $date
*/
public function seeDateWasYesterday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isYesterday());
}
/**
* See date was not yesterdays date.
*
* @param string $date
*/
public function dontSeeDateWasYesterday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isYesterday());
}
/**
* See date is in a given number of days.
*
* @param string $date
* @param int $days
*/
public function seeDateIsInDays($date, $days) {
\PHPUnit_Framework_Assert::assertEquals($days, $this->_GetNow()->diffInDays($this->_ParseDate($date), false));
}
/**
* See date is not in a given number of days.
*
* @param string $date
* @param int $days
*/
public function dontSeeDateIsInDays($date, $days) {
\PHPUnit_Framework_Assert::assertNotEquals($days, $this->_GetNow()->diffInDays($this->_ParseDate($date), false));
}
/**
* See date was in a given number of days.
*
* @param string $date
* @param int $days
*/
public function seeDateWasInDays($date, $days) {
\PHPUnit_Framework_Assert::assertEquals($days, $this->_ParseDate($date)->diffInDays($this->_GetNow(), false));
}
/**
* See date was in a given number of days.
*
* @param string $date
* @param int $days
*/
public function dontSeeDateWasInDays($date, $days) {
\PHPUnit_Framework_Assert::assertNotEquals($days, $this->_ParseDate($date)->diffInDays($this->_GetNow(), false));
}
/* ----------------- Weeks ----------------- */
/**
* See date is next week.
*
* @param string $date
*/
public function seeDateIsNextWeek($date) {
$this->seeDateIsInWeeks($date, 1);
}
/**
* See date is not next week.
*
* @param string $date
*/
public function dontSeeDateIsNextWeek($date) {
$this->dontSeeDateIsInWeeks($date, 1);
}
/**
* See date is in a given number of weeks.
*
* @param string $date
* @param int $weeks
*/
public function seeDateIsInWeeks($date, $weeks) {
\PHPUnit_Framework_Assert::assertEquals($weeks, $this->_GetNow()->diffInWeeks($this->_ParseDate($date), false));
}
/**
* See date is in a given number of weeks.
*
* @param string $date
* @param int $weeks
*/
public function dontSeeDateIsInWeeks($date, $weeks) {
\PHPUnit_Framework_Assert::assertNotEquals($weeks, $this->_GetNow()->diffInWeeks($this->_ParseDate($date), false));
}
/**
* See date was last week.
*
* @param string $date
*/
public function seeDateWasLastWeek($date) {
$this->seeDateWasInWeeks($date, 1);
}
/**
* See date was not last week.
*
* @param string $date
*/
public function dontSeeDateWasLastWeek($date) {
$this->dontSeeDateWasInWeeks($date, 1);
}
/**
* See date was in a given number of weeks.
*
* @param string $date
* @param int $weeks
*/
public function seeDateWasInWeeks($date, $weeks) {
\PHPUnit_Framework_Assert::assertEquals($weeks, $this->_ParseDate($date)->diffInWeeks($this->_GetNow(), false));
}
/**
* See date was in a given number of weeks.
*
* @param string $date
* @param int $weeks
*/
public function dontSeeDateWasInWeeks($date, $weeks) {
\PHPUnit_Framework_Assert::assertNotEquals($weeks, $this->_ParseDate($date)->diffInWeeks($this->_GetNow(), false));
}
/* ----------------- Months ----------------- */
/**
* See date is next month.
*
* @param string $date
*/
public function seeDateIsNextMonth($date) {
$this->seeDateIsInMonths($date, 1);
}
/**
* See date is not next month.
*
* @param string $date
*/
public function dontSeeDateIsNextMonth($date) {
$this->dontSeeDateIsInMonths($date, 1);
}
/**
* See date is in a given number of months.
*
* @param string $date
* @param int $months
*/
public function seeDateIsInMonths($date, $months) {
\PHPUnit_Framework_Assert::assertEquals($months, $this->_GetNow()->diffInMonths($this->_ParseDate($date), false));
}
/**
* See date is not in a given number of months.
*
* @param string $date
* @param int $months
*/
public function dontSeeDateIsInMonths($date, $months) {
\PHPUnit_Framework_Assert::assertNotEquals($months, $this->_GetNow()->diffInMonths($this->_ParseDate($date), false));
}
/**
* See date was last month.
*
* @param string $date
*/
public function seeDateWasLastMonth($date) {
$this->seeDateWasInMonths($date, 1);
}
/**
* See date was not last month.
*
* @param string $date
*/
public function dontSeeDateWasLastMonth($date) {
$this->dontSeeDateWasInMonths($date, 1);
}
/**
* See date was in a given number of months.
*
* @param string $date
* @param int $months
*/
public function seeDateWasInMonths($date, $months) {
\PHPUnit_Framework_Assert::assertEquals($months, $this->_ParseDate($date)->diffInMonths($this->_GetNow(), false));
}
/**
* See date was not in a given number of years.
*
* @param string $date
* @param int $months
*/
public function dontSeeDateWasInMonths($date, $months) {
\PHPUnit_Framework_Assert::assertNotEquals($months, $this->_ParseDate($date)->diffInMonths($this->_GetNow(), false));
}
/* ----------------- Years ----------------- */
/**
* See date is next year.
*
* @param string $date
*/
public function seeDateIsNextYear($date) {
$this->seeDateIsInYears($date, 1);
}
/**
* See date is not next year.
*
* @param string $date
*/
public function dontSeeDateIsNextYear($date) {
$this->dontSeeDateIsInYears($date, 1);
}
/**
* See date is in a given number of years.
*
* @param string $date
* @param int $years
*/
public function seeDateIsInYears($date, $years) {
\PHPUnit_Framework_Assert::assertEquals($years, $this->_GetNow()->diffInYears($this->_ParseDate($date), false));
}
/**
* See date is in not a given number of years.
*
* @param string $date
* @param int $years
*/
public function dontSeeDateIsInYears($date, $years) {
\PHPUnit_Framework_Assert::assertNotEquals($years, $this->_GetNow()->diffInYears($this->_ParseDate($date), false));
}
/**
* See date was last year.
*
* @param string $date
*/
public function seeDateWasLastYear($date) {
$this->seeDateWasInYears($date, 1);
}
/**
* See date was not last year.
*
* @param string $date
*/
public function dontSeeDateWasLastYear($date) {
$this->dontSeeDateWasInYears($date, 1);
}
/**
* See date was in a given number of years.
*
* @param string $date
* @param int $years
*/
public function seeDateWasInYears($date, $years) {
\PHPUnit_Framework_Assert::assertEquals($years, $this->_ParseDate($date)->diffInYears($this->_GetNow(), false));
}
/**
* See date was not in a given number of years.
*
* @param string $date
* @param int $years
*/
public function dontSeeDateWasInYears($date, $years) {
\PHPUnit_Framework_Assert::assertNotEquals($years, $this->_ParseDate($date)->diffInYears($this->_GetNow(), false));
}
/* ----------------- Days of the Week ----------------- */
/**
* See date is a Monday.
*
* @param string $date
*/
public function seeDateIsMonday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::MONDAY);
}
/**
* See date is not a Monday.
*
* @param string $date
*/
public function dontSeeDateIsMonday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::MONDAY);
}
/**
* See date is a Tuesday.
*
* @param string $date
*/
public function seeDateIsTuesday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::TUESDAY);
}
/**
* See date is not a Tuesday.
*
* @param string $date
*/
public function dontSeeDateIsTuesday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::TUESDAY);
}
/**
* See date is a Wednesday.
*
* @param string $date
*/
public function seeDateIsWednesday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::WEDNESDAY);
}
/**
* See date is not a Wednesday.
*
* @param string $date
*/
public function dontSeeDateIsWednesday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::WEDNESDAY);
}
/**
* See date is a Thursday.
*
* @param string $date
*/
public function seeDateIsThursday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::THURSDAY);
}
/**
* See date is not a Thursday.
*
* @param string $date
*/
public function dontSeeDateIsThursday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::THURSDAY);
}
/**
* See date is a Friday
*
* @param string $date
*/
public function seeDateIsFriday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::FRIDAY);
}
/**
* See date is not a Friday.
*
* @param string $date
*/
public function dontSeeDateIsFriday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::FRIDAY);
}
/**
* See date is a Saturday.
*
* @param string $date
*/
public function seeDateIsSaturday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::SATURDAY);
}
/**
* See date is not a Saturday.
*
* @param string $date
*/
public function dontSeeDateIsSaturday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::SATURDAY);
}
/**
* See date is a Sunday.
*
* @param string $date
*/
public function seeDateIsSunday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->dayOfWeek == Carbon::SUNDAY);
}
/**
* See date is not a Sunday.
*
* @param string $date
*/
public function dontSeeDateIsSunday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->dayOfWeek == Carbon::SUNDAY);
}
/* ----------------- Days Grouping ----------------- */
/**
* See date is a weekday.
*
* @param string $date
*/
public function seeDateIsWeekday($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isWeekday());
}
/**
* See date is not a weekday.
*
* @param string $date
*/
public function dontSeeDateIsWeekday($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isWeekday());
}
/**
* See date is a weekend.
*
* @param string $date
*/
public function seeDateIsWeekend($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isWeekend());
}
/**
* See date is not a weekend.
*
* @param string $date
*/
public function dontSeeDateIsWeekend($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isWeekend());
}
/* ----------------- Exact Matches ----------------- */
/**
* See that two dates match.
*
* @param string $d1
* @param string $d2
*/
public function seeDateMatches($d1, $d2) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($d1)->eq($this->_ParseDate($d2)));
}
/**
* See that two dates don't match.
*
* @param string $d1
* @param string $d2
*/
public function dontSeeDateMatches($d1, $d2) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($d1)->ne($this->_ParseDate($d2)));
}
/* ----------------- Future/Past Matches ----------------- */
/**
* See the date is in the future.
*
* @param string $date
*/
public function seeDateInFuture($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isFuture());
}
/**
* See the date is not in the future.
*
* @param string $date
*/
public function dontSeeDateInFuture($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isFuture());
}
/**
* See the date is in the past.
*
* @param string $date
*/
public function seeDateInPast($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isPast());
}
/**
* See the date is not in the past.
*
* @param string $date
*/
public function dontSeeDateInPast($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isPast());
}
/* ----------------- Quarters ----------------- */
/**
* See the date is within the first quarter of the year.
*
* @param string $date
*/
public function seeDateInFirstQuarter($date) {
$this->seeDateInQuarter($date, 1);
}
/**
* See the date is not within the first quarter of the year.
*
* @param string $date
*/
public function dontSeeDateInFirstQuarter($date) {
$this->dontSeeDateInQuarter($date, 1);
}
/**
* See the date is within the second quarter of the year.
*
* @param string $date
*/
public function seeDateInSecondQuarter($date) {
$this->seeDateInQuarter($date, 2);
}
/**
* See the date is not within the second quarter of the year.
*
* @param string $date
*/
public function donSeeDateInSecondQuarter($date) {
$this->dontSeeDateInQuarter($date, 2);
}
/**
* See the date is within the third quarter of the year.
*
* @param string $date
*/
public function seeDateInThirdQuarter($date) {
$this->seeDateInQuarter($date, 3);
}
/**
* See the date is not within the third quarter of the year.
*
* @param string $date
*/
public function dontSeeDateInThirdQuarter($date) {
$this->dontSeeDateInQuarter($date, 3);
}
/**
* See the date is within the forth quarter of the year.
*
* @param string $date
*/
public function seeDateInFourthQuarter($date) {
$this->seeDateInQuarter($date, 4);
}
/**
* See the date is not within the forth quarter of the year.
*
* @param string $date
*/
public function dontSeeDateInFourthQuarter($date) {
$this->dontSeeDateInQuarter($date, 4);
}
/**
* See the date is within a particular quarter of the year.
*
* @param string $date
* @param int $quarter
*/
public function seeDateInQuarter($date, $quarter) {
\PHPUnit_Framework_Assert::assertEquals($quarter, $this->_ParseDate($date)->quarter);
}
/**
* See the date is not within a particular quarter of the year.
*
* @param string $date
* @param int $quarter
*/
public function dontSeeDateInQuarter($date, $quarter) {
\PHPUnit_Framework_Assert::assertNotEquals($quarter, $this->_ParseDate($date)->quarter);
}
/* ----------------- Years ----------------- */
/**
* See the date is a leap year.
*
* @param string $date
*/
public function seeDateIsLeapYear($date) {
\PHPUnit_Framework_Assert::assertTrue($this->_ParseDate($date)->isLeapYear());
}
/**
* See the date is not a leap year.
*
* @param string $date
*/
public function dontSeeDateIsLeapYear($date) {
\PHPUnit_Framework_Assert::assertFalse($this->_ParseDate($date)->isLeapYear());
}
/* ----------------- Day In ----------------- */
/**
* See the date is a given day in the week.
*
* @param string $date
* @param int $day
*/
public function seeDayInWeek($date, $day) {
\PHPUnit_Framework_Assert::assertEquals($day, $this->_ParseDate($date)->dayOfWeek);
}
/**
* See the date is not a given day in the week.
*
* @param string $date
* @param int $day
*/
public function dontSeeDayInWeek($date, $day) {
\PHPUnit_Framework_Assert::assertNotEquals($day, $this->_ParseDate($date)->dayOfWeek);
}
/**
* See the date is a given day in the month.
*
* @param string $date
* @param int $day
*/
public function seeDayInMonth($date, $day) {
\PHPUnit_Framework_Assert::assertEquals($day, $this->_ParseDate($date)->day);
}
/**
* See the date is not a given day in the month.
*
* @param string $date
* @param int $day
*/
public function dontSeeDayInMonth($date, $day) {
\PHPUnit_Framework_Assert::assertNotEquals($day, $this->_ParseDate($date)->day);
}
/**
* See the date is a given day in the year.
*
* @param string $date
* @param int $day
*/
public function seeDayInYear($date, $day) {
\PHPUnit_Framework_Assert::assertEquals($day, $this->_ParseDate($date)->dayOfYear);
}
/**
* See the date is not a given day in the year.
*
* @param string $date
* @param int $day
*/
public function dontSeeDayInYear($date, $day) {
\PHPUnit_Framework_Assert::assertNotEquals($day, $this->_ParseDate($date)->dayOfYear);
}
/* ----------------- Week In ----------------- */
/**
* See the date is a not given week in the month.
*
* @param string $date
* @param int $week
*/
public function seeWeekInMonth($date, $week) {
\PHPUnit_Framework_Assert::assertEquals($week, $this->_ParseDate($date)->weekOfMonth);
}
/**
* See the date is a not given week in the month.
*
* @param string $date
* @param int $week
*/
public function dontSeeWeekInMonth($date, $week) {
\PHPUnit_Framework_Assert::assertNotEquals($week, $this->_ParseDate($date)->weekOfMonth);
}
/**
* See the date is a given week in the year.
*
* @param string $date
* @param int $week
*/
public function seeWeekInYear($date, $week) {
\PHPUnit_Framework_Assert::assertEquals($week, $this->_ParseDate($date)->weekOfYear);
}
/**
* See the date is not a given week in the year.
*
* @param string $date
* @param int $week
*/
public function dontSeeWeekInYear($date, $week) {
\PHPUnit_Framework_Assert::assertNotEquals($week, $this->_ParseDate($date)->weekOfYear);
}
/* ----------------- Month In ----------------- */
/**
* See the month in the year is a given value.
*
* @param string $date
* @param int $month
*/
public function seeMonthInYear($date, $month) {
\PHPUnit_Framework_Assert::assertEquals($month, $this->_ParseDate($date)->month);
}
/**
* See the month in the year is not a given value.
*
* @param string $date
* @param int $month
*/
public function dontSeeMonthInYear($date, $month)
{
\PHPUnit_Framework_Assert::assertNotEquals($month, $this->_ParseDate($date)->month);
}
/* ----------------- System Helpers ----------------- */
/**
* Parse the date input to format the datetime object.
*
* @param string $date
*
* @return Carbon
*/
private function _ParseDate($date) {
return Carbon::parse($date);
}
/**
* Return the current date.
*
* @return Carbon
*/
private function _GetNow() {
return Carbon::now();
}
}