forked from uniplaces/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carbon_test.go
2762 lines (1938 loc) · 72.1 KB
/
carbon_test.go
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package carbon
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAddYearsPositive(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddYears(10)
expected, _ := Create(2019, time.November, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2019")
}
func TestAddYearsZero(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddYears(0)
expected, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2009")
}
func TestAddYearsNegative(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddYears(-10)
expected, _ := Create(1999, time.November, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 1999")
}
func TestAddYear(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddYear()
expected, _ := Create(2010, time.November, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2010")
}
func TestAddQuartersPositive(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddQuarters(2)
expected, _ := Create(2010, time.May, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to May of 2010")
}
func TestAddQuartersZero(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddQuarters(0)
expected, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to November")
}
func TestAddQuartersNegative(t *testing.T) {
c, _ := Create(2009, time.November, 10, 23, 0, 0, 0, "UTC")
d := c.AddQuarters(-2)
expected, _ := Create(2009, time.May, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to May")
}
func TestAddQuarter(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddQuarter()
expected, _ := Create(2010, time.April, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to June of 2010")
}
func TestAddCenturiesPositive(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddCenturies(3)
expected, _ := Create(2310, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal 2110")
}
func TestAddCenturiesZero(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddCenturies(0)
expected, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal 2010")
}
func TestAddCenturiesNegative(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddCenturies(-2)
expected, _ := Create(1810, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal 1810")
}
func TestAddCentury(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddCentury()
expected, _ := Create(2110, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal 2110")
}
func TestAddMonthsPositive(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddMonths(2)
expected, _ := Create(2010, time.March, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to March")
}
func TestAddMonthsZero(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddMonths(0)
expected, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal January")
}
func TestAddMonthsNegative(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddMonths(-3)
expected, _ := Create(2009, time.October, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to October")
}
func TestAddMonth(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddMonth()
expected, _ := Create(2010, time.February, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The Month should be equal to February")
}
func TestAddSecondsPositive(t *testing.T) {
c, _ := Create(2010, time.January, 10, 22, 59, 0, 0, "UTC")
d := c.AddSeconds(70)
expected, _ := Create(2010, time.January, 10, 23, 0, 10, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 10")
}
func TestAddSecondsZero(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddSeconds(0)
expected, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 0")
}
func TestAddSecondsNegative(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddSeconds(-20)
expected, _ := Create(2010, time.January, 10, 22, 59, 40, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 40")
}
func TestAddSecond(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddSecond()
expected, _ := Create(2010, time.January, 10, 23, 0, 1, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 1")
}
func TestAddDaysPositive(t *testing.T) {
c, _ := Create(2010, time.January, 10, 22, 59, 0, 0, "UTC")
d := c.AddDays(10)
expected, _ := Create(2010, time.January, 20, 22, 59, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 20")
}
func TestAddDaysZero(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddDays(0)
expected, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 23")
}
func TestAddDaysNegative(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddDays(-10)
expected, _ := Create(2009, time.December, 31, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 31")
}
func TestAddDay(t *testing.T) {
c, _ := Create(2010, time.January, 10, 23, 0, 0, 0, "UTC")
d := c.AddDay()
expected, _ := Create(2010, time.January, 11, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 11")
}
func TestAddWeekdaysPositive(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeekdays(5)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 12")
}
func TestAddWeekdaysZero(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeekdays(0)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 5")
}
func TestAddWeekdaysNegative(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeekdays(-5)
expected, _ := Create(2016, time.July, 29, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 29")
}
func TestAddWeekday(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeekday()
expected, _ := Create(2016, time.August, 8, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 8")
}
func TestAddWeeksPositive(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeeks(2)
expected, _ := Create(2016, time.August, 19, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 19")
}
func TestAddWeeksZero(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeeks(0)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 5")
}
func TestAddWeeksNegative(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeeks(-2)
expected, _ := Create(2016, time.July, 22, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 22")
}
func TestAddWeek(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddWeek()
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 12")
}
func TestAddHoursPositive(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddHours(10)
expected, _ := Create(2016, time.August, 5, 20, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 20")
}
func TestAddHoursZero(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddHours(0)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 10")
}
func TestAddHoursNegative(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddHours(-11)
expected, _ := Create(2016, time.August, 4, 23, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 23")
}
func TestAddHour(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddHour()
expected, _ := Create(2016, time.August, 5, 11, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 11")
}
func TestAddMinutesZero(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddMinutes(0)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 0")
}
func TestAddMinutesPositive(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddMinutes(50)
expected, _ := Create(2016, time.August, 5, 10, 50, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 50")
}
func TestAddMinutesNegative(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddMinutes(-50)
expected, _ := Create(2016, time.August, 5, 9, 10, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 50")
}
func TestAddMinute(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddMinute()
expected, _ := Create(2016, time.August, 5, 10, 1, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 1")
}
func TestAddMonthsNoOverflowZero(t *testing.T) {
c, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
d := c.AddMonthsNoOverflow(0)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to August")
}
func TestAddMonthsNoOverflowPositive(t *testing.T) {
c, _ := Create(2016, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.AddMonthsNoOverflow(2)
expected, _ := Create(2016, time.March, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to March")
}
func TestAddMonthsNoOverflowPositiveWithOverflow(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.AddMonthsNoOverflow(1)
expected, _ := Create(2012, time.February, 29, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to February")
}
func TestAddMonthsNoOverflowNegative(t *testing.T) {
c, _ := Create(2012, time.February, 29, 1, 0, 0, 0, "UTC")
d := c.AddMonthsNoOverflow(-2)
expected, _ := Create(2011, time.December, 29, 1, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to December")
}
func TestAddMonthsNoOverflowNegativeWithOverflow(t *testing.T) {
c, _ := Create(2012, time.March, 31, 1, 0, 0, 0, "UTC")
d := c.AddMonthsNoOverflow(-1)
expected, _ := Create(2012, time.February, 29, 1, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to February")
}
func TestAddMonthNoOverflow(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.AddMonthNoOverflow()
expected, _ := Create(2012, time.February, 29, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to February")
}
func TestPreviousMonthLastDay(t *testing.T) {
c, _ := Create(2016, time.March, 31, 10, 0, 0, 0, "UTC")
d := c.PreviousMonthLastDay()
expected, _ := Create(2016, time.February, 29, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 29")
}
func TestSubYearsZero(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubYears(0)
expected, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2012")
}
func TestSubYearsPositive(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubYears(2)
expected, _ := Create(2010, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2010")
}
func TestSubYearsNegative(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubYears(-2)
expected, _ := Create(2014, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2015")
}
func TestSubYear(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubYear()
expected, _ := Create(2011, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2011")
}
func TestSubQuartersZero(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubQuarters(0)
expected, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to January")
}
func TestSubQuartersPositive(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubQuarters(2)
expected, _ := Create(2011, time.July, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to July")
}
func TestSubQuartersNegative(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubQuarters(-2)
expected, _ := Create(2012, time.July, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to July")
}
func TestSubQuarter(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubQuarter()
expected, _ := Create(2011, time.October, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to October")
}
func TestSubCenturiesZero(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubCenturies(0)
expected, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2012")
}
func TestSubCenturiesPositive(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubCenturies(2)
expected, _ := Create(1712, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 1712")
}
func TestSubCenturiesNegative(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubCenturies(-2)
expected, _ := Create(2112, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 2112")
}
func TestSubCentury(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubCentury()
expected, _ := Create(1812, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The year should be equal to 1812")
}
func TestSubMonthsZero(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonths(0)
expected, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to January")
}
func TestSubMonthsPositive(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonths(2)
expected, _ := Create(1911, time.November, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to November")
}
func TestSubMonthsNegative(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonths(-2)
expected, _ := Create(1912, time.March, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to March")
}
func TestSubMonth(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonth()
expected, _ := Create(1911, time.December, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to December")
}
func TestSubMonthsNoOverflowZero(t *testing.T) {
c, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonthsNoOverflow(0)
expected, _ := Create(2012, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to January")
}
func TestSubMonthsNoOverflowPositive(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonthsNoOverflow(2)
expected, _ := Create(1911, time.November, 30, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to November")
}
func TestSubMonthsNoOverflowNegative(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonthsNoOverflow(-2)
expected, _ := Create(1912, time.March, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to March")
}
func TestSubMonthNoOverflow(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubMonthNoOverflow()
expected, _ := Create(1911, time.December, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The month should be equal to December")
}
func TestSubDaysZero(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubDays(0)
expected, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 31")
}
func TestSubDaysPositive(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubDays(10)
expected, _ := Create(1912, time.January, 21, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 21")
}
func TestSubDaysNegative(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubDays(-10)
expected, _ := Create(1912, time.February, 10, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 10")
}
func TestSubDay(t *testing.T) {
c, _ := Create(1912, time.January, 31, 10, 0, 0, 0, "UTC")
d := c.SubDay()
expected, _ := Create(1912, time.January, 30, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 30")
}
func TestSubWeekdayZero(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeekdays(0)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 12")
}
func TestSubWeekdayPositive(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeekdays(5)
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 5")
}
func TestSubWeekdayNegative(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeekdays(-5)
expected, _ := Create(2016, time.August, 19, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 19")
}
func TestSubWeekday(t *testing.T) {
c, _ := Create(2016, time.August, 15, 10, 0, 0, 0, "UTC")
d := c.SubWeekday()
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 12")
}
func TestSubWeeksZero(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeeks(0)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 12")
}
func TestSubWeeksPositive(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeeks(2)
expected, _ := Create(2016, time.July, 29, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 29")
}
func TestSubWeeksNegative(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeeks(-1)
expected, _ := Create(2016, time.August, 19, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 19")
}
func TestSubWeek(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubWeek()
expected, _ := Create(2016, time.August, 5, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The day should be equal to 5")
}
func TestSubHoursZero(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubHours(0)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 10")
}
func TestSubHoursPositive(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubHours(10)
expected, _ := Create(2016, time.August, 12, 0, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 0")
}
func TestSubHoursNegative(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubHours(-10)
expected, _ := Create(2016, time.August, 12, 20, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 20")
}
func TestSubHour(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubHour()
expected, _ := Create(2016, time.August, 12, 9, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 9")
}
func TestSubMinutesZero(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubMinutes(0)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The hour should be equal to 10")
}
func TestSubMinutesPositive(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 20, 0, 0, "UTC")
d := c.SubMinutes(10)
expected, _ := Create(2016, time.August, 12, 10, 10, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 10")
}
func TestSubMinutesNegative(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 20, 0, 0, "UTC")
d := c.SubMinutes(-10)
expected, _ := Create(2016, time.August, 12, 10, 30, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 30")
}
func TestSubMinute(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 20, 0, 0, "UTC")
d := c.SubMinute()
expected, _ := Create(2016, time.August, 12, 10, 19, 0, 0, "UTC")
assert.Equal(t, expected, d, "The minutes should be equal to 19")
}
func TestSubSecondsZero(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
d := c.SubSeconds(0)
expected, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 0")
}
func TestSubSecondsPositive(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
d := c.SubSeconds(10)
expected, _ := Create(2016, time.August, 12, 10, 0, 20, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 20")
}
func TestSubSecondsNegative(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
d := c.SubSeconds(-10)
expected, _ := Create(2016, time.August, 12, 10, 0, 40, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 40")
}
func TestSubSecond(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
d := c.SubSecond()
expected, _ := Create(2016, time.August, 12, 10, 0, 29, 0, "UTC")
assert.Equal(t, expected, d, "The seconds should be equal to 29")
}
func TestSetters(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetYear(2010)
c.SetMonth(time.May)
c.SetDay(2)
c.SetHour(5)
c.SetMinute(10)
c.SetSecond(10)
expected, _ := Create(2010, time.May, 2, 5, 10, 10, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2010-05-02 5h 10m 10s")
}
func TestSetDate(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetDate(2015, time.May, 30)
expected, _ := Create(2015, time.May, 30, 10, 0, 30, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2015-05-02")
}
func TestSetDateTime(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetDateTime(2010, time.May, 2, 5, 10, 10)
expected, _ := Create(2010, time.May, 2, 5, 10, 10, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2010-05-02 5h 10m 10s")
}
func TestSetTimeFromTimeStringHour(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 0, 0, "UTC")
err := c.SetTimeFromTimeString("20")
expected, _ := Create(2016, time.August, 12, 20, 0, 0, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2010-05-02 20h 0m 0s")
assert.Nil(t, err)
}
func TestSetTimeFromTimeStringMinute(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
err := c.SetTimeFromTimeString("20:20")
expected, _ := Create(2016, time.August, 12, 20, 20, 30, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2010-05-02 20h 30m 0s")
assert.Nil(t, err)
}
func TestSetTimeFromTimeStringSecond(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
err := c.SetTimeFromTimeString("20:20:20")
expected, _ := Create(2016, time.August, 12, 20, 20, 20, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 2010-05-02 20h 20m 20s")
assert.Nil(t, err)
}
func TestSetTimeFromTimeStringEmpty(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
err := c.SetTimeFromTimeString("")
assert.NotNil(t, err)
}
func TestSetTimeFromTimeStringInvalid(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
err := c.SetTimeFromTimeString("10-10-10")
assert.NotNil(t, err)
}
func TestSetWeekEndsAt(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetWeekEndsAt(time.Monday)
assert.Equal(t, time.Monday, c.WeekEndsAt(), "The end of the week should be Monday")
}
func TestSetWeekStartsAt(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetWeekStartsAt(time.Sunday)
assert.Equal(t, time.Sunday, c.WeekStartsAt(), "The start of the week should be Sunday")
}
func TestSetWeekendDays(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
wds := []time.Weekday{
time.Sunday,
time.Monday,
}
c.SetWeekendDays(wds)
assert.Equal(t, wds, c.WeekendDays(), "The start of the week should be Sunday")
}
func TestSetTimezone(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetTimeZone("Europe/Lisbon")
assert.Equal(t, "Europe/Lisbon", c.TimeZone(), "The start of the week should be Sunday")
}
func TestSetTimezoneError(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
err := c.SetTimeZone("Mars/Wonderland")
assert.NotNil(t, err)
}
func TestSetTimestamp(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetTimestamp(1171502725)
expected, _ := Create(2007, time.February, 15, 1, 25, 25, 0, "UTC")
assert.Equal(t, expected, c, "The date should be 07-02-15 01:25:25")
}
func TestResetStringFormat(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
c.SetStringFormat(time.Kitchen)
c.ResetStringFormat()
assert.Equal(t, "2016-08-12 10:00:30", c.String())
}
func TestDateString(t *testing.T) {
c, _ := Create(2016, time.August, 12, 10, 0, 30, 0, "UTC")
assert.Equal(t, "2016-08-12", c.DateString())
}
func TestFormattedDateString(t *testing.T) {
c, _ := Create(2016, time.August, 2, 10, 0, 30, 0, "UTC")
assert.Equal(t, "Aug 2, 2016", c.FormattedDateString())
}
func TestTimeString(t *testing.T) {
c, _ := Create(2016, time.August, 2, 10, 0, 30, 0, "UTC")
assert.Equal(t, "10:00:30", c.TimeString())
}
func TestDateTimeString(t *testing.T) {
c, _ := Create(2016, time.August, 2, 10, 0, 30, 0, "UTC")
assert.Equal(t, "2016-08-02 10:00:30", c.DateTimeString())
}
func TestDayDateTimeString(t *testing.T) {
c, _ := Create(2016, time.August, 8, 1, 0, 30, 0, "UTC")
assert.Equal(t, "Mon, Aug 8, 2016 1:00 AM", c.DayDateTimeString())
}