-
Notifications
You must be signed in to change notification settings - Fork 162
/
test.js
1033 lines (916 loc) · 39.8 KB
/
test.js
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
var chai = require('chai')
, moment = require('./index')
chai.should()
moment.updateLocale('en'
, { week:
{ dow: 6
, doy: 12
}
, longDateFormat:
{ LT: 'h:mm A'
, LTS: 'h:mm:ss A'
, L: 'jYYYY/jMM/jDD'
, LL: 'jD jMMMM jYYYY'
, LLL: 'jD jMMMM jYYYY LT'
, LLLL: 'dddd, jD jMMMM jYYYY LT'
}
}
)
describe('moment', function() {
describe('#parse', function() {
it('should parse gregorian dates', function() {
var m = moment('1980/5/15 07:10:20', 'YYYY/M/D hh:mm:ss')
m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('1980-05-15 07:10:20')
m.milliseconds().should.be.equal(0)
})
it('should parse correctly when input is only time', function() {
var m = moment('07:10:20', 'hh:mm:ss')
m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('0000-01-01 07:10:20')
})
it('should parse when only Jalaali year is in the format', function() {
var m = moment('05 1359 15', 'MM jYYYY DD')
m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
m = moment('05 59 15', 'MM jYY DD')
m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
})
it('should parse when only Jalaali month is in the format', function() {
var m = moment('1980 2 15', 'YYYY jM D')
m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
})
it('should parse when only Jalaali month string is in the format', function() {
var m = moment('1980 Ord 15', 'YYYY jMMM D')
m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
m = moment('1980 Ordibehesht 15', 'YYYY jMMMM D')
m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
})
it('should parse when only Jalaali date is in the format', function() {
var m = moment('1980 24 5', 'YYYY jD M')
m.format('YYYY-MM-DD').should.be.equal('1980-05-13')
})
it('should parse when Jalaali year and month are in the format', function() {
var m = moment('15 1359 2', 'D jYYYY jM')
m.format('YYYY-MM-DD').should.be.equal('1980-04-15')
m = moment('1392 7', 'jYYYY jM')
m.format('YYYY-MM-DD').should.be.equal('2013-09-23')
})
it('should parse when Jalaali year and date are in the format', function() {
var m = moment('24 1359 5', 'jD jYYYY M')
m.format('YYYY-MM-DD').should.be.equal('1980-05-13')
})
it('should parse when Jalaali month and date are in the format', function() {
var m = moment('24 1980 2', 'jD YYYY jM')
m.format('YYYY-MM-DD').should.be.equal('1980-05-14')
})
it('should parse when Jalaali year, month and date are in the format', function() {
var m = moment('24 1359 2', 'jD jYYYY jM')
m.format('YYYY-MM-DD').should.be.equal('1980-05-14')
})
it('should parse with complex format', function() {
var m = moment('15 24 50 1980 50 5 12', 'D jD jYYYY YYYY M M jM')
m.format('YYYY-MM-DD').should.be.equal('1980-05-15')
})
it('should parse format result', function() {
var f = 'jYYYY/jM/jD hh:mm:ss.SSS a'
, m = moment()
moment(m.format(f), f).isSame(m).should.be.true
})
it('should be able to parse in utc', function() {
var m = moment.utc('1359/2/24 07:10:20', 'jYYYY/jM/jD hh:mm:ss')
m.format('YYYY-MM-DD hh:mm:ss Z').should.be.equal('1980-05-14 07:10:20 +00:00')
})
it('should parse with a format array', function() {
var p1 = 'jYY jM jD'
, p2 = 'jM jD jYY'
, p3 = 'jD jYY jM'
, m
m = moment('60 11 12', ['D YY M', 'M D YY', 'YY M D'])
m.format('YY-MM-DD').should.be.equal('60-11-12')
m = moment('10 11 12', [p1, p2, p3])
m.format('jYY-jMM-jDD').should.be.equal('10-11-12')
m = moment('10 11 12', [p2, p3, p1])
m.format('jYY-jMM-jDD').should.be.equal('12-10-11')
m = moment('10 11 12', [p3, p1, p2])
m.format('jYY-jMM-jDD').should.be.equal('11-12-10')
m = moment('10 11 12', [p3, p2, p1])
m.format('jYY-jMM-jDD').should.be.equal('11-12-10')
m = moment('60-11-12', [p3, p2, p1])
m.format('jYY-jMM-jDD').should.be.equal('60-11-12')
m = moment('60 11 12', [p3, p2, p1])
m.format('jYY-jMM-jDD').should.be.equal('60-11-12')
m = moment('60 8 31', ['YY M D', 'jYY jM jD'])
m.format('YY-MM-DD').should.be.equal('60-08-31')
m = moment('60 8 31', ['jYY jM jD', 'YY M D'])
m.format('YY-MM-DD').should.be.equal('60-08-31')
m = moment('60 5 31', ['YY M D', 'jYY jM jD'])
m.format('YY-MM-DD').should.be.equal('60-05-31')
m = moment('60 5 31', ['jYY jM jD', 'YY M D'])
m.format('jYY-jMM-jDD').should.be.equal('60-05-31')
})
it('should return valid moment instance if years is less than 3178', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.format('jYYYY-jMM-jDD').should.be.equal('3177-01-01')
})
it('should return invalid moment instance if years is larger than 3177 (Jalali)', function () {
var m = moment('3178-01-01', 'jYYYY-jMM-jDD')
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (Gregorian)', function () {
var m = moment('9999-01-01','YYYY-MM-DD')
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (timestamp)', function () {
var m = moment(64060576200000)
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (timestamp)', function () {
var m = moment(new Date(64060576200000))
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
})
describe('#format', function() {
it('should work normally when there is no Jalaali token', function() {
var m = moment('1980-05-15 07:10:20')
m.format('YYYY-MM-DD hh:mm:ss').should.be.equal('1980-05-15 07:10:20')
})
it('should format to Jalaali with Jalaali tokens', function() {
var m = moment('1980-05-15 07:10:20')
m.format('jYYYY-jMM-jDD hh:mm:ss').should.be.equal('1359-02-25 07:10:20')
})
it('should format with escaped and unescaped tokens', function() {
var m = moment('1980-05-15')
m.format('[My] birt\\h \\y[ea]r [is] jYYYY or YYYY').should.be.equal('My birth year is 1359 or 1980')
})
it('should format with mixed tokens', function() {
var m = moment('1980-05-15')
m.format('jYYYY/jMM/jDD = YYYY-MM-DD').should.be.equal('1359/02/25 = 1980-05-15')
})
it('should format with jMo', function() {
var m = moment('1980-05-15')
m.format('jMo').should.be.equal('2nd')
})
it('should format with jM', function() {
var m = moment('1980-05-15')
m.format('jM').should.be.equal('2')
})
it('should format with jMM', function() {
var m = moment('1980-05-15')
m.format('jMM').should.be.equal('02')
})
it('should format with jMMM', function() {
var m = moment('1980-05-15')
m.format('jMMM').should.be.equal('Ord')
})
it('should format with jMMMM', function() {
var m = moment('1980-05-15')
m.format('jMMMM').should.be.equal('Ordibehesht')
})
it('should format with jDo', function() {
var m = moment('1980-05-15')
m.format('jDo').should.be.equal('25th')
})
it('should format with jD', function() {
var m = moment('1980-05-15')
m.format('jD').should.be.equal('25')
})
it('should format with jDD', function() {
var m = moment('1980-05-15')
m.format('jDD').should.be.equal('25')
m = moment('1980-05-22')
m.format('jDD').should.be.equal('01')
})
it('should format with jDDD', function() {
var m = moment('1980-05-15')
m.format('jDDD').should.be.equal('56')
})
it('should format with jDDDo', function() {
var m = moment('1980-05-15')
m.format('jDDDo').should.be.equal('56th')
})
it('should format with jDDDD', function() {
var m = moment('1980-05-15')
m.format('jDDDD').should.be.equal('056')
m = moment('1980-03-21')
m.format('jDDDD').should.be.equal('001')
})
it('should format with jwo', function() {
var m = moment('1980-05-15')
m.format('jwo').should.be.equal('9th')
})
it('should format with jw', function() {
var m = moment('1980-05-15')
m.format('jw').should.be.equal('9')
})
it('should format with jww', function() {
var m = moment('1980-05-15')
m.format('jww').should.be.equal('09')
m = moment('1980-04-23')
m.format('jww').should.be.equal('06')
})
it('should format with jYY', function() {
var m = moment('1980-05-15')
m.format('jYY').should.be.equal('59')
})
it('should format with jYYYY', function() {
var m = moment('1980-05-15')
m.format('jYYYY').should.be.equal('1359')
})
it('should format with jYYYYY', function() {
var m = moment('1980-05-15')
m.format('jYYYYY').should.be.equal('01359')
})
it('should format with jgg', function() {
var m = moment('1980-05-15')
m.format('jgg').should.be.equal('59')
})
it('should format with jgggg', function() {
var m = moment('1980-05-15')
m.format('jgggg').should.be.equal('1359')
})
it('should format with jggggg', function() {
var m = moment('1980-05-15')
m.format('jggggg').should.be.equal('01359')
})
it('should work with long date formats too', function() {
var m = moment('1980-05-15')
m.format('LT').should.be.equal('12:00 AM')
m.format('LTS').should.be.equal('12:00:00 AM')
m.format('L').should.be.equal('1359/02/25')
m.format('l').should.be.equal('1359/2/25')
m.format('LL').should.be.equal('25 Ordibehesht 1359')
m.format('ll').should.be.equal('25 Ord 1359')
m.format('LLL').should.be.equal('25 Ordibehesht 1359 12:00 AM')
m.format('lll').should.be.equal('25 Ord 1359 12:00 AM')
m.format('LLLL').should.be.equal('Thursday, 25 Ordibehesht 1359 12:00 AM')
m.format('llll').should.be.equal('Thu, 25 Ord 1359 12:00 AM')
})
it('should work with long date formats too if we have time', function() {
var m = moment('1980-05-15 12:15:45')
m.format('LT').should.be.equal('12:15 PM')
m.format('LTS').should.be.equal('12:15:45 PM')
m.format('L').should.be.equal('1359/02/25')
m.format('l').should.be.equal('1359/2/25')
m.format('LL').should.be.equal('25 Ordibehesht 1359')
m.format('ll').should.be.equal('25 Ord 1359')
m.format('LLL').should.be.equal('25 Ordibehesht 1359 12:15 PM')
m.format('lll').should.be.equal('25 Ord 1359 12:15 PM')
m.format('LLLL').should.be.equal('Thursday, 25 Ordibehesht 1359 12:15 PM')
m.format('llll').should.be.equal('Thu, 25 Ord 1359 12:15 PM')
})
})
describe('#jYear', function() {
it('should return Jalaali year', function() {
var m = moment('1980-05-15')
m.jYear().should.be.equal(1359)
})
it('should set Jalaali year', function() {
var m = moment('1980-05-15')
m.jYear(1392)
m.format('jYYYY/jM/jD').should.be.equal('1392/2/25')
m = moment('2013-03-20')
m.format('jYY/jM/jD').should.be.equal('91/12/30')
m.jYear(1392)
m.format('jYY/jM/jD').should.be.equal('92/12/29')
})
it('should also has jYears alias', function() {
moment.fn.jYear.should.be.equal(moment.fn.jYears)
})
it('should return invalid moment instance if years is larger than 31778', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.jYear(3178)
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
})
describe('#jMonth', function() {
it('should return Jalaali month', function() {
var m = moment('1980-05-15')
m.jMonth().should.be.equal(1)
})
it('should set Jalaali month', function() {
var m = moment('1980-05-15')
m.jMonth(4)
m.format('jYYYY/jM/jD').should.be.equal('1359/5/25')
m = moment('2012-05-20')
m.format('jYY/jM/jD').should.be.equal('91/2/31')
m.jMonth(11)
m.format('jYY/jM/jD').should.be.equal('91/12/30')
m = moment('2013-05-21')
m.format('jYY/jM/jD').should.be.equal('92/2/31')
m.jMonth(11)
m.format('jYY/jM/jD').should.be.equal('92/12/29')
})
it('should also has jMonths alias', function() {
moment.fn.jMonth.should.be.equal(moment.fn.jMonths)
})
})
describe('#jDate', function() {
it('should return Jalaali date', function() {
var m = moment('1980-05-15')
m.jDate().should.be.equal(25)
})
it('should set Jalaali date', function() {
var m = moment('1980-05-15')
m.jDate(30)
m.format('jYYYY/jM/jD').should.be.equal('1359/2/30')
m = moment('2013-03-01')
m.format('jYY/jM/jD').should.be.equal('91/12/11')
m.jDate(29)
m.format('jYY/jM/jD').should.be.equal('91/12/29')
m.jDate(30)
m.format('jYY/jM/jD').should.be.equal('91/12/30')
m.jDate(30)
m.format('jYY/jM/jD').should.be.equal('91/12/30')
m.jDate(31)
m.format('jYY/jM/jD').should.be.equal('92/1/1')
m.jDate(90)
m.format('jYY/jM/jD').should.be.equal('92/3/28')
})
it('should also has jDates alias', function() {
moment.fn.jDate.should.be.equal(moment.fn.jDates)
})
})
describe('#jDayOfYear', function() {
it('should return Jalaali date of year', function() {
var m = moment('1980-05-15')
m.jDayOfYear().should.be.equal(56)
m = moment('1981-03-21')
m.jDayOfYear().should.be.equal(1)
m = moment('1982-03-20')
m.jDayOfYear().should.be.equal(365)
m = moment('1984-03-20')
m.jDayOfYear().should.be.equal(366)
})
it('should set Jalaali date of year', function() {
var m = moment('1980-05-15')
m.jDayOfYear(30)
m.format('jYYYY/jM/jD').should.be.equal('1359/1/30')
m.jDayOfYear(364)
m.format('jYY/jM/jD').should.be.equal('59/12/28')
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('59/12/29')
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('60/1/1')
m.jDayOfYear(1)
m.format('jYY/jM/jD').should.be.equal('60/1/1')
m.jDayOfYear(90)
m.format('jYY/jM/jD').should.be.equal('60/3/28')
m.jDayOfYear(365 + 365)
m.format('jYY/jM/jD').should.be.equal('61/12/29')
})
})
describe('#jWeek', function() {
it('should return Jalaali week of year', function() {
var m = moment('1980-05-15')
m.jWeek().should.be.equal(9)
m.jDayOfYear(1)
m.format('jYY/jM/jD').should.be.equal('59/1/1')
m.jWeek().should.be.equal(1)
m.jDayOfYear(8)
m.format('jYY/jM/jD').should.be.equal('59/1/8')
m.jWeek().should.be.equal(2)
m.jDayOfYear(14)
m.format('jYY/jM/jD').should.be.equal('59/1/14')
m.jWeek().should.be.equal(3)
m.jDayOfYear(364)
m.format('jYY/jM/jD').should.be.equal('59/12/28')
m.jWeek().should.be.equal(53)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('59/12/29')
m.jWeek().should.be.equal(53)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('60/1/1')
m.jWeek().should.be.equal(1)
m.jDayOfYear(363)
m.format('jYY/jM/jD').should.be.equal('60/12/27')
m.jWeek().should.be.equal(52)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('60/12/29')
m.jWeek().should.be.equal(1)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('61/1/1')
m.jWeek().should.be.equal(1)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('61/12/29')
m.jWeek().should.be.equal(1)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('61/12/29')
m.jWeek().should.be.equal(1)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('62/1/1')
m.jWeek().should.be.equal(1)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('62/12/29')
m.jWeek().should.be.equal(1)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('62/12/30')
m.jWeek().should.be.equal(1)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('62/12/29')
m.jWeek().should.be.equal(1)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('62/12/30')
m.jWeek().should.be.equal(1)
m.jDayOfYear(358)
m.format('jYY/jM/jD').should.be.equal('62/12/22')
m.jWeek().should.be.equal(52)
m.jDayOfYear(359)
m.format('jYY/jM/jD').should.be.equal('62/12/23')
m.jWeek().should.be.equal(52)
m.jDayOfYear(360)
m.format('jYY/jM/jD').should.be.equal('62/12/24')
m.jWeek().should.be.equal(52)
m.jDayOfYear(361)
m.format('jYY/jM/jD').should.be.equal('62/12/25')
m.jWeek().should.be.equal(52)
m.jDayOfYear(362)
m.format('jYY/jM/jD').should.be.equal('62/12/26')
m.jWeek().should.be.equal(52)
m.jDayOfYear(363)
m.format('jYY/jM/jD').should.be.equal('62/12/27')
m.jWeek().should.be.equal(1)
m.jDayOfYear(364)
m.format('jYY/jM/jD').should.be.equal('62/12/28')
m.jWeek().should.be.equal(1)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('62/12/29')
m.jWeek().should.be.equal(1)
})
it('should set Jalaali week of year', function() {
var m = moment('1980-05-15')
m.jWeek(1)
m.format('jYY/jM/jD').should.be.equal('58/12/30')
m.jWeek(9)
m.format('jYY/jM/jD').should.be.equal('59/2/25')
m.jWeek(52)
m.format('jYY/jM/jD').should.be.equal('59/12/21')
m.jWeek(53)
m.format('jYY/jM/jD').should.be.equal('59/12/28')
m.jWeek(1)
m.format('jYY/jM/jD').should.be.equal('58/12/30')
m.jWeek(0)
m.format('jYY/jM/jD').should.be.equal('58/12/23')
m.jWeek(-1)
m.format('jYY/jM/jD').should.be.equal('57/12/17')
})
})
describe('#jWeekYear', function() {
it('should return Jalaali week year', function() {
var m = moment('1980-05-15')
m.jWeekYear().should.be.equal(1359)
m.jDayOfYear(1)
m.format('jYY/jM/jD').should.be.equal('59/1/1')
m.jWeekYear().should.be.equal(1359)
m.jDayOfYear(364)
m.format('jYY/jM/jD').should.be.equal('59/12/28')
m.jWeekYear().should.be.equal(1359)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('59/12/29')
m.jWeekYear().should.be.equal(1359)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('60/1/1')
m.jWeekYear().should.be.equal(1360)
m.jDayOfYear(363)
m.format('jYY/jM/jD').should.be.equal('60/12/27')
m.jWeekYear().should.be.equal(1360)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('60/12/29')
m.jWeekYear().should.be.equal(1361)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('61/1/1')
m.jWeekYear().should.be.equal(1361)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('61/12/29')
m.jWeekYear().should.be.equal(1362)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('62/1/1')
m.jWeekYear().should.be.equal(1362)
m.jDayOfYear(367)
m.format('jYY/jM/jD').should.be.equal('63/1/1')
m.jWeekYear().should.be.equal(1363)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('63/12/29')
m.jWeekYear().should.be.equal(1364)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('64/1/1')
m.jWeekYear().should.be.equal(1364)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('64/12/29')
m.jWeekYear().should.be.equal(1365)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('65/1/1')
m.jWeekYear().should.be.equal(1365)
m.jDayOfYear(358)
m.format('jYY/jM/jD').should.be.equal('65/12/22')
m.jWeekYear().should.be.equal(1365)
m.jDayOfYear(359)
m.format('jYY/jM/jD').should.be.equal('65/12/23')
m.jWeekYear().should.be.equal(1365)
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('65/12/29')
m.jWeekYear().should.be.equal(1365)
m.jDayOfYear(366)
m.format('jYY/jM/jD').should.be.equal('66/1/1')
m.jWeekYear().should.be.equal(1366)
})
it('should set Jalaali week year', function() {
var m = moment('1980-05-15')
m.jWeekYear(1360)
m.format('jYY/jM/jD').should.be.equal('60/2/25')
m.jWeekYear(1364)
m.format('jYY/jM/jD').should.be.equal('64/2/25')
m.jDayOfYear(365)
m.format('jYY/jM/jD').should.be.equal('64/12/29')
m.jWeekYear(1364)
m.format('jYY/jM/jD').should.be.equal('63/12/29')
m.jWeekYear(1365)
m.format('jYY/jM/jD').should.be.equal('64/12/29')
})
})
describe('#startOf', function() {
it('should work as expected without jYear and jMonth', function() {
var m = moment('1980-05-15 07:10:20')
m.startOf('year').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-01-01 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('month').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-01 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('day').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-15 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-10 00:00:00')
})
it('should return start of Jalaali year, month and date', function() {
var m = moment('1985-05-15 07:10:20')
m.startOf('jYear').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1364-01-01 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('jMonth').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-01 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('day').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-25 00:00:00')
m = moment('1980-05-15 07:10:20')
m.startOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-20 00:00:00')
})
})
describe('#endOf', function() {
it('should work as expected without jYear and jMonth', function() {
var m = moment('1980-05-15 07:10:20')
m.endOf('year').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-12-31 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('month').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-31 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('day').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-15 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('week').format('YYYY-MM-DD HH:mm:ss').should.be.equal('1980-05-16 23:59:59')
})
it('should return end of Jalaali year, month and date', function() {
var m = moment('1985-05-15 07:10:20')
m.endOf('jYear').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1364-12-29 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('jMonth').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-31 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('day').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-25 23:59:59')
m = moment('1980-05-15 07:10:20')
m.endOf('week').format('jYYYY-jMM-jDD HH:mm:ss').should.be.equal('1359-02-26 23:59:59')
})
})
describe('#isValid', function() {
it('should return true when a valid date is parsed and false otherwise', function() {
var jf = 'jYYYY/jMM/jDD'
, gf = 'YYYY-MM-DD'
moment('1980-05-15', gf).isValid().should.be.true
moment('1980-05-29', gf).isValid().should.be.true
moment('1980-06-31', gf).isValid().should.be.false
moment('1359 xordibehesht 25', 'jYYYY jMMMM jD').isValid().should.be.false
moment('1359/02/25', jf).isValid().should.be.true
moment('1359/02/31', jf).isValid().should.be.true
moment('1359/04/30', jf).isValid().should.be.true
moment('1359/04/32', jf).isValid().should.be.false
moment('1359/12/29', jf).isValid().should.be.true
moment('1359/12/30', jf).isValid().should.be.false
moment('1359/12/31', jf).isValid().should.be.false
moment('1359/13/01', jf).isValid().should.be.false
moment('1393/11/00', jf).isValid().should.be.false
})
})
describe('#isValid-strict', function () {
it('should return false when gregorian date is not strictly valid', function () {
var gf = 'YYYY-MM-DD'
moment('1980-05-15', gf).isValid().should.be.true
moment('1980-05-31', gf).isValid().should.be.true
moment('1980-05-311', gf).isValid().should.be.true
moment('1980-05-311', gf, true).isValid().should.be.false
})
it('should return false when jalaali date is not strictly valid', function () {
var jf = 'jYYYY/jMM/jDD'
moment('1359/02/25', jf).isValid().should.be.true
moment('1359/02/31', jf).isValid().should.be.true
moment('1359/02/311', jf, true).isValid().should.be.false
})
})
describe('#clone', function() {
it('should return a cloned instance', function() {
var m = moment('1359/2/25', 'jYYYY/jM/jD')
, c = m.clone()
m.add(1, 'jYear')
m.add(5, 'day')
m.format('jYY/jM/jD').should.be.equal('60/2/30')
c.format('jYY/jM/jD').should.be.equal('59/2/25')
})
})
describe('#add', function () {
it('should add gregorian dates correctly', function () {
var gf = 'YYYY-M-D'
, m = moment('1980-5-15', 'YYYY-M-D')
moment(m).add(1, 'day').format(gf).should.be.equal('1980-5-16')
moment(m).add(10, 'days').format(gf).should.be.equal('1980-5-25')
moment(m).add(30, 'days').format(gf).should.be.equal('1980-6-14')
moment(m).add(60, 'days').format(gf).should.be.equal('1980-7-14')
moment(m).add(1, 'month').format(gf).should.be.equal('1980-6-15')
moment(m).add(2, 'months').format(gf).should.be.equal('1980-7-15')
moment(m).add(10, 'months').format(gf).should.be.equal('1981-3-15')
moment(m).add(20, 'months').format(gf).should.be.equal('1982-1-15')
moment(m).add(1, 'year').format(gf).should.be.equal('1981-5-15')
moment(m).add(2, 'years').format(gf).should.be.equal('1982-5-15')
moment(m).add(10, 'years').format(gf).should.be.equal('1990-5-15')
moment(m).add(20, 'years').format(gf).should.be.equal('2000-5-15')
})
it('should add jalaali dates correctly', function () {
var jf = 'jYYYY/jM/jD'
, m = moment('1359/2/25', 'jYYYY/jM/jD')
moment(m).add(1, 'day').format(jf).should.be.equal('1359/2/26')
moment(m).add(4, 'days').format(jf).should.be.equal('1359/2/29')
moment(m).add(10, 'days').format(jf).should.be.equal('1359/3/4')
moment(m).add(30, 'days').format(jf).should.be.equal('1359/3/24')
moment(m).add(60, 'days').format(jf).should.be.equal('1359/4/23')
moment(m).add(365, 'days').format(jf).should.be.equal('1360/2/25')
moment(m).add(1, 'jmonth').format(jf).should.be.equal('1359/3/25')
moment(m).add(2, 'jmonths').format(jf).should.be.equal('1359/4/25')
moment(m).add(10, 'jmonths').format(jf).should.be.equal('1359/12/25')
moment(m).add(20, 'jmonths').format(jf).should.be.equal('1360/10/25')
moment(m).add(1, 'jyear').format(jf).should.be.equal('1360/2/25')
moment(m).add(2, 'jyears').format(jf).should.be.equal('1361/2/25')
moment(m).add(3, 'jyears').format(jf).should.be.equal('1362/2/25')
moment(m).add(4, 'jyears').format(jf).should.be.equal('1363/2/25')
moment(m).add(10, 'jyears').format(jf).should.be.equal('1369/2/25')
moment(m).add(20, 'jyears').format(jf).should.be.equal('1379/2/25')
})
it('should retain last day of month when adding months or years', function () {
var jf = 'jYYYY/jM/jD'
, m = moment('1393/6/31', jf)
moment(m).add(1, 'jmonth').format(jf).should.be.equal('1393/7/30')
moment(m).add(5, 'jmonth').format(jf).should.be.equal('1393/11/30')
moment(m).add(6, 'jmonth').format(jf).should.be.equal('1393/12/29')
m = moment('1391/12/30', jf)
moment(m).add(1, 'jyear').format(jf).should.be.equal('1392/12/29')
moment(m).add(2, 'jyear').format(jf).should.be.equal('1393/12/29')
moment(m).add(3, 'jyear').format(jf).should.be.equal('1394/12/29')
moment(m).add(4, 'jyear').format(jf).should.be.equal('1395/12/30')
})
it('should return invalid moment instance if years is larger than 3177 (add year)', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.add(1, 'jyear')
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (add month)', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.add(12, 'jmonth')
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (add day)', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.add(365, 'day')
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
it('should return invalid moment instance if years is larger than 3177 (add seconds)', function () {
var m = moment('3177-01-01', 'jYYYY-jMM-jDD')
m.add(365 * 3600 * 24, 'seconds') // 365 days
m.isValid().should.be.false
m.jYear().should.be.NaN
m.jMonth().should.be.NaN
m.jDate().should.be.NaN
})
})
describe('#subtract', function () {
it('should subtract gregorian dates correctly', function () {
var gf = 'YYYY-M-D'
, m = moment('1980-5-15', 'YYYY-M-D')
moment(m).subtract(1, 'day').format(gf).should.be.equal('1980-5-14')
moment(m).subtract(10, 'days').format(gf).should.be.equal('1980-5-5')
moment(m).subtract(30, 'days').format(gf).should.be.equal('1980-4-15')
moment(m).subtract(60, 'days').format(gf).should.be.equal('1980-3-16')
moment(m).subtract(1, 'month').format(gf).should.be.equal('1980-4-15')
moment(m).subtract(2, 'months').format(gf).should.be.equal('1980-3-15')
moment(m).subtract(10, 'months').format(gf).should.be.equal('1979-7-15')
moment(m).subtract(20, 'months').format(gf).should.be.equal('1978-9-15')
moment(m).subtract(1, 'year').format(gf).should.be.equal('1979-5-15')
moment(m).subtract(2, 'years').format(gf).should.be.equal('1978-5-15')
moment(m).subtract(10, 'years').format(gf).should.be.equal('1970-5-15')
moment(m).subtract(20, 'years').format(gf).should.be.equal('1960-5-15')
})
it('should subtract jalaali dates correctly', function () {
var jf = 'jYYYY/jM/jD'
, m = moment('1359/2/25', 'jYYYY/jM/jD')
moment(m).subtract(1, 'day').format(jf).should.be.equal('1359/2/24')
moment(m).subtract(4, 'days').format(jf).should.be.equal('1359/2/21')
moment(m).subtract(10, 'days').format(jf).should.be.equal('1359/2/15')
moment(m).subtract(30, 'days').format(jf).should.be.equal('1359/1/26')
moment(m).subtract(60, 'days').format(jf).should.be.equal('1358/12/26')
moment(m).subtract(365, 'days').format(jf).should.be.equal('1358/2/26')
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1359/1/25')
moment(m).subtract(2, 'jmonths').format(jf).should.be.equal('1358/12/25')
moment(m).subtract(10, 'jmonths').format(jf).should.be.equal('1358/4/25')
moment(m).subtract(20, 'jmonths').format(jf).should.be.equal('1357/6/25')
moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1358/2/25')
moment(m).subtract(2, 'jyears').format(jf).should.be.equal('1357/2/25')
moment(m).subtract(3, 'jyears').format(jf).should.be.equal('1356/2/25')
moment(m).subtract(4, 'jyears').format(jf).should.be.equal('1355/2/25')
moment(m).subtract(10, 'jyears').format(jf).should.be.equal('1349/2/25')
moment(m).subtract(20, 'jyears').format(jf).should.be.equal('1339/2/25')
})
it('should retain last day of month when subtracting months or years', function () {
var jf = 'jYYYY/jM/jD'
, m = moment('1393/1/31', jf)
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/29')
moment(m).subtract(6, 'jmonth').format(jf).should.be.equal('1392/7/30')
moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/31')
m = moment('1391/12/30', jf)
moment(m).subtract(1, 'jyear').format(jf).should.be.equal('1390/12/29')
moment(m).subtract(2, 'jyear').format(jf).should.be.equal('1389/12/29')
moment(m).subtract(3, 'jyear').format(jf).should.be.equal('1388/12/29')
moment(m).subtract(4, 'jyear').format(jf).should.be.equal('1387/12/30')
})
it('should subtract months correctly', function () {
var jf = 'jYYYY/jM/jD'
, m = moment('1393/1/31', jf)
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/29')
moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/30')
moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/31')
moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/31')
moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/30')
moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/29')
m = moment('1393/1/1', jf)
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/1')
moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/1')
moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/1')
moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/1')
moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/1')
moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/1')
m = moment('1393/1/10', jf)
moment(m).subtract(1, 'jmonth').format(jf).should.be.equal('1392/12/10')
moment(m).subtract(2, 'jmonth').format(jf).should.be.equal('1392/11/10')
moment(m).subtract(7, 'jmonth').format(jf).should.be.equal('1392/6/10')
moment(m).subtract(12, 'jmonth').format(jf).should.be.equal('1392/1/10')
moment(m).subtract(13, 'jmonth').format(jf).should.be.equal('1391/12/10')
moment(m).subtract(25, 'jmonth').format(jf).should.be.equal('1390/12/10')
})
})
describe('.jIsLeapYear', function() {
it('should return true for Jalaali leap years and false otherwise', function() {
moment.jIsLeapYear(1391).should.be.true
moment.jIsLeapYear(1392).should.be.false
moment.jIsLeapYear(1393).should.be.false
moment.jIsLeapYear(1394).should.be.false
moment.jIsLeapYear(1395).should.be.true
moment.jIsLeapYear(1396).should.be.false
moment.jIsLeapYear(1397).should.be.false
moment.jIsLeapYear(1398).should.be.false
moment.jIsLeapYear(1399).should.be.true
moment.jIsLeapYear(1400).should.be.false
moment.jIsLeapYear(1401).should.be.false
moment.jIsLeapYear(1402).should.be.false
moment.jIsLeapYear(1403).should.be.true
moment.jIsLeapYear(1404).should.be.false
})
})
describe('.loadPersian', function() {
it('should load Persian lang', function() {
var ol = moment.locale()
, m
moment.loadPersian()
m = moment('1980-05-15')
m.format('D MMMM YYYY').should.be.equal('15 مه 1980')
m.format('jD jMMMM jYYYY').should.be.equal('25 اردیبهشت 1359')
m.calendar().should.be.equal('1359/02/25')
m.format('LLLL').should.be.equal('پنجشنبه، 25 اردیبهشت 1359 00:00')
m.format('llll').should.be.equal('پنجشنبه، 25 ارد 1359 00:00')
moment.locale(ol)
})
})
describe('.loadPersian({usePersianDigits: true})', function() {
it('should load Persian lang with usePersianDigits = true', function() {
var ol = moment.locale()
, m
moment.loadPersian({usePersianDigits: true})
m = moment('1980-05-15')
m.format('D MMMM YYYY').should.be.equal('۱۵ مه ۱۹۸۰')
m.format('jD jMMMM jYYYY').should.be.equal('۲۵ اردیبهشت ۱۳۵۹')
m.calendar().should.be.equal('۱۳۵۹/۰۲/۲۵')
m.format('LLLL').should.be.equal('پنجشنبه، ۲۵ اردیبهشت ۱۳۵۹ ۰۰:۰۰')
m.format('llll').should.be.equal('پنجشنبه، ۲۵ ارد ۱۳۵۹ ۰۰:۰۰')
moment.locale(ol)
})
})
describe('.loadPersian({dialect: persian-modern})', function() {
it('should load Persian lang with dialect = persian-modern', function() {
var ol = moment.locale()
, m
moment.loadPersian({dialect: 'persian-modern'})
m = moment('1980-05-19')
m.format('D MMMM YYYY').should.be.equal('19 مه 1980')
m.format('jD jMMMM jYYYY').should.be.equal('29 اردیبهشت 1359')
m.calendar().should.be.equal('1359/02/29')
m.format('LLLL').should.be.equal('دوشنبه، 29 اردیبهشت 1359 00:00')
m.format('llll').should.be.equal('دوشنبه، 29 ارد 1359 00:00')
m.format('dd lll').should.be.equal('د 29 ارد 1359 00:00')
moment.locale(ol)
})
})
describe('.unix', function () {
it('should create a moment with unix epoch', function () {
var unix = moment('1359/2/25', 'jYYYY/jM/jD').unix()
moment.unix(unix).format('jYYYY/jM/jD').should.be.equal('1359/2/25')
})
})
describe('#isSame', function () {
it('should work correctly for same year', function () {
var m1 = moment('2016-02-04')
var m2 = moment('2016-01-01')
var m3 = moment('2015-12-31')
var m4 = moment('2017-01-01')
m1.isSame(m2, 'year').should.be.true
m1.isSame(m3, 'year').should.be.false
m1.isSame(m4, 'year').should.be.false
m2.isSame(m3, 'year').should.be.false
m2.isSame(m4, 'year').should.be.false
m3.isSame(m4, 'year').should.be.false
})
it('should work correctly for same month', function () {
var m1 = moment('2016-02-04')
var m2 = moment('2016-02-01')
var m3 = moment('2016-01-01')
var m4 = moment('2016-03-01')
m1.isSame(m2, 'month').should.be.true
m1.isSame(m3, 'month').should.be.false
m1.isSame(m4, 'month').should.be.false
m2.isSame(m3, 'month').should.be.false
m2.isSame(m4, 'month').should.be.false
m3.isSame(m4, 'month').should.be.false
})
it('should work correctly for same day', function () {
var m1 = moment('2016-02-04 06:00')
var m2 = moment('2016-02-04 07:00')
var m3 = moment('2016-02-03 06:00')
var m4 = moment('2016-02-05 06:00')
m1.isSame(m2, 'day').should.be.true
m1.isSame(m3, 'day').should.be.false