summaryrefslogtreecommitdiff
path: root/date-fns/src/format/test.js
blob: 97ad0032a5e8a55ea535248e7efafb3c75602d65 (plain)
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
// @flow
/* eslint-env mocha */

import assert from 'power-assert'
import format from '.'

describe('format', function () {
  var date = new Date(1986, 3 /* Apr */, 4, 10, 32, 55, 123)

  var offset = date.getTimezoneOffset()
  var absoluteOffset = Math.abs(offset)
  var hours = Math.floor(absoluteOffset / 60)
  var hoursLeadingZero = hours < 10 ? '0' : ''
  var minutes = absoluteOffset % 60
  var minutesLeadingZero = minutes < 10 ? '0' : ''
  var sign = offset > 0 ? '-' : '+'

  var timezone =
    sign + hoursLeadingZero + hours + ':' + minutesLeadingZero + minutes
  var timezoneShort = timezone.replace(':', '')
  var timezoneWithOptionalMinutesShort =
    minutes === 0 ? sign + hoursLeadingZero + hours : timezoneShort

  var timezoneWithZ = offset === 0 ? 'Z' : timezone
  var timezoneWithZShort = offset === 0 ? 'Z' : timezoneShort
  var timezoneWithOptionalMinutesAndZShort =
    offset === 0 ? 'Z' : timezoneWithOptionalMinutesShort

  var timezoneGMTShort =
    minutes === 0
      ? 'GMT' + sign + hours
      : 'GMT' + sign + hours + ':' + minutesLeadingZero + minutes
  var timezoneGMT = 'GMT' + timezone

  var timestamp = date.getTime().toString()
  var secondsTimestamp = Math.floor(date.getTime() / 1000).toString()

  it('accepts a timestamp', function () {
    var date = new Date(2014, 3, 4).getTime()
    assert(format(date, 'yyyy-MM-dd') === '2014-04-04')
  })

  it('escapes characters between the single quote characters', function () {
    var result = format(date, "'yyyy-'MM-dd'THH:mm:ss.SSSX' yyyy-'MM-dd'")
    assert(result === 'yyyy-04-04THH:mm:ss.SSSX 1986-MM-dd')
  })

  it('two single quote characters are transformed into a "real" single quote', function () {
    var date = new Date(2014, 3, 4, 5)
    assert(format(date, "''h 'o''clock'''") === "'5 o'clock'")
  })

  it('accepts new line charactor', function () {
    var date = new Date(2014, 3, 4, 5)
    assert.equal(format(date, "yyyy-MM-dd'\n'HH:mm:ss"), '2014-04-04\n05:00:00')
  })

  describe('ordinal numbers', function () {
    it('ordinal day of an ordinal month', function () {
      var result = format(date, "do 'day of the' Mo 'month of' yyyy")
      assert(result === '4th day of the 4th month of 1986')
    })

    it('should return a correct ordinal number', function () {
      var result = []
      for (var i = 1; i <= 31; i++) {
        result.push(format(new Date(2015, 0, i), 'do'))
      }
      var expected = [
        '1st',
        '2nd',
        '3rd',
        '4th',
        '5th',
        '6th',
        '7th',
        '8th',
        '9th',
        '10th',
        '11th',
        '12th',
        '13th',
        '14th',
        '15th',
        '16th',
        '17th',
        '18th',
        '19th',
        '20th',
        '21st',
        '22nd',
        '23rd',
        '24th',
        '25th',
        '26th',
        '27th',
        '28th',
        '29th',
        '30th',
        '31st',
      ]
      assert.deepEqual(result, expected)
    })
  })

  it('era', function () {
    var result = format(date, 'G GG GGG GGGG GGGGG')
    assert(result === 'AD AD AD Anno Domini A')
  })

  describe('year', function () {
    describe('regular year', function () {
      it('works as expected', function () {
        var result = format(date, 'y yo yy yyy yyyy yyyyy')
        assert(result === '1986 1986th 86 1986 1986 01986')
      })

      it('1 BC formats as 1', function () {
        var date = new Date(0)
        date.setFullYear(0, 0 /* Jan */, 1)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'y')
        assert(result === '1')
      })

      it('2 BC formats as 2', function () {
        var date = new Date(0)
        date.setFullYear(-1, 0 /* Jan */, 1)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'y')
        assert(result === '2')
      })
    })

    describe('local week-numbering year', function () {
      it('works as expected', function () {
        var result = format(date, 'Y Yo YY YYY YYYY YYYYY', {
          useAdditionalWeekYearTokens: true,
        })
        assert(result === '1986 1986th 86 1986 1986 01986')
      })

      it('the first week of the next year', function () {
        var result = format(new Date(2013, 11 /* Dec */, 29), 'YYYY', {
          useAdditionalWeekYearTokens: true,
        })
        assert(result === '2014')
      })

      it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in options', function () {
        var result = format(new Date(2013, 11 /* Dec */, 29), 'YYYY', {
          weekStartsOn: 1,
          firstWeekContainsDate: 4,
          useAdditionalWeekYearTokens: true,
        })
        assert(result === '2013')
      })

      it('the first week of year', function () {
        var result = format(new Date(2016, 0 /* Jan */, 1), 'YYYY', {
          useAdditionalWeekYearTokens: true,
        })
        assert(result === '2016')
      })

      it('1 BC formats as 1', function () {
        var date = new Date(0)
        date.setFullYear(0, 6 /* Jul */, 2)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'Y')
        assert(result === '1')
      })

      it('2 BC formats as 2', function () {
        var date = new Date(0)
        date.setFullYear(-1, 6 /* Jul */, 2)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'Y')
        assert(result === '2')
      })
    })

    describe('ISO week-numbering year', function () {
      it('works as expected', function () {
        var result = format(date, 'R RR RRR RRRR RRRRR')
        assert(result === '1986 1986 1986 1986 01986')
      })

      it('the first week of the next year', function () {
        var result = format(new Date(2013, 11 /* Dec */, 30), 'RRRR')
        assert(result === '2014')
      })

      it('the last week of the previous year', function () {
        var result = format(new Date(2016, 0 /* Jan */, 1), 'RRRR')
        assert(result === '2015')
      })

      it('1 BC formats as 0', function () {
        var date = new Date(0)
        date.setFullYear(0, 6 /* Jul */, 2)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'R')
        assert(result === '0')
      })

      it('2 BC formats as -1', function () {
        var date = new Date(0)
        date.setFullYear(-1, 6 /* Jul */, 2)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'R')
        assert(result === '-1')
      })
    })

    describe('extended year', function () {
      it('works as expected', function () {
        var result = format(date, 'u uu uuu uuuu uuuuu')
        assert(result === '1986 1986 1986 1986 01986')
      })

      it('1 BC formats as 0', function () {
        var date = new Date(0)
        date.setFullYear(0, 0, 1)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'u')
        assert(result === '0')
      })

      it('2 BC formats as -1', function () {
        var date = new Date(0)
        date.setFullYear(-1, 0, 1)
        date.setHours(0, 0, 0, 0)
        var result = format(date, 'u')
        assert(result === '-1')
      })
    })
  })

  describe('quarter', function () {
    it('formatting quarter', function () {
      var result = format(date, 'Q Qo QQ QQQ QQQQ QQQQQ')
      assert(result === '2 2nd 02 Q2 2nd quarter 2')
    })

    it('stand-alone quarter', function () {
      var result = format(date, 'q qo qq qqq qqqq qqqqq')
      assert(result === '2 2nd 02 Q2 2nd quarter 2')
    })

    it('returns a correct quarter for each month', function () {
      var result = []
      for (var i = 0; i <= 11; i++) {
        result.push(format(new Date(1986, i, 1), 'Q'))
      }
      var expected = [
        '1',
        '1',
        '1',
        '2',
        '2',
        '2',
        '3',
        '3',
        '3',
        '4',
        '4',
        '4',
      ]
      assert.deepEqual(result, expected)
    })
  })

  describe('month', function () {
    it('formatting month', function () {
      var result = format(date, 'M Mo MM MMM MMMM MMMMM')
      assert(result === '4 4th 04 Apr April A')
    })

    it('stand-alone month', function () {
      var result = format(date, 'L Lo LL LLL LLLL LLLLL')
      assert(result === '4 4th 04 Apr April A')
    })
  })

  describe('week', function () {
    describe('local week of year', function () {
      it('works as expected', function () {
        var date = new Date(1986, 3 /* Apr */, 6)
        var result = format(date, 'w wo ww')
        assert(result === '15 15th 15')
      })

      it('allows to specify `weekStartsOn` and `firstWeekContainsDate` in options', function () {
        var date = new Date(1986, 3 /* Apr */, 6)
        var result = format(date, 'w wo ww', {
          weekStartsOn: 1,
          firstWeekContainsDate: 4,
        })
        assert(result === '14 14th 14')
      })
    })

    it('ISO week of year', function () {
      var date = new Date(1986, 3 /* Apr */, 6)
      var result = format(date, 'I Io II')
      assert(result === '14 14th 14')
    })
  })

  describe('day', function () {
    it('date', function () {
      var result = format(date, 'd do dd')
      assert(result === '4 4th 04')
    })

    describe('day of year', function () {
      it('works as expected', function () {
        var result = format(date, 'D Do DD DDD DDDDD', {
          useAdditionalDayOfYearTokens: true,
        })
        assert(result === '94 94th 94 094 00094')
      })

      it('returns a correct day number for the last day of a leap year', function () {
        var result = format(
          new Date(1992, 11 /* Dec */, 31, 23, 59, 59, 999),
          'D',
          { useAdditionalDayOfYearTokens: true }
        )
        assert(result === '366')
      })
    })
  })

  describe('week day', function () {
    describe('day of week', function () {
      it('works as expected', function () {
        var result = format(date, 'E EE EEE EEEE EEEEE EEEEEE')
        assert(result === 'Fri Fri Fri Friday F Fr')
      })
    })

    describe('ISO day of week', function () {
      it('works as expected', function () {
        var result = format(date, 'i io ii iii iiii iiiii iiiiii')
        assert(result === '5 5th 05 Fri Friday F Fr')
      })

      it('returns a correct day of an ISO week', function () {
        var result = []
        for (var i = 1; i <= 7; i++) {
          result.push(format(new Date(1986, 8 /* Sep */, i), 'i'))
        }
        var expected = ['1', '2', '3', '4', '5', '6', '7']
        assert.deepEqual(result, expected)
      })
    })

    describe('formatting day of week', function () {
      it('works as expected', function () {
        var result = format(date, 'e eo ee eee eeee eeeee eeeeee')
        assert(result === '6 6th 06 Fri Friday F Fr')
      })

      it('by default, 1 is Sunday, 2 is Monday, ...', function () {
        var result = []
        for (var i = 7; i <= 13; i++) {
          result.push(format(new Date(1986, 8 /* Sep */, i), 'e'))
        }
        var expected = ['1', '2', '3', '4', '5', '6', '7']
        assert.deepEqual(result, expected)
      })

      it('allows to specify which day is the first day of the week', function () {
        var result = []
        for (var i = 1; i <= 7; i++) {
          result.push(
            format(new Date(1986, 8 /* Sep */, i), 'e', { weekStartsOn: 1 })
          )
        }
        var expected = ['1', '2', '3', '4', '5', '6', '7']
        assert.deepEqual(result, expected)
      })
    })

    describe('stand-alone day of week', function () {
      it('works as expected', function () {
        var result = format(date, 'c co cc ccc cccc ccccc cccccc')
        assert(result === '6 6th 06 Fri Friday F Fr')
      })

      it('by default, 1 is Sunday, 2 is Monday, ...', function () {
        var result = []
        for (var i = 7; i <= 13; i++) {
          result.push(format(new Date(1986, 8 /* Sep */, i), 'c'))
        }
        var expected = ['1', '2', '3', '4', '5', '6', '7']
        assert.deepEqual(result, expected)
      })

      it('allows to specify which day is the first day of the week', function () {
        var result = []
        for (var i = 1; i <= 7; i++) {
          result.push(
            format(new Date(1986, 8 /* Sep */, i), 'c', { weekStartsOn: 1 })
          )
        }
        var expected = ['1', '2', '3', '4', '5', '6', '7']
        assert.deepEqual(result, expected)
      })
    })
  })

  describe('day period and hour', function () {
    it('hour [1-12]', function () {
      var result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'h ho hh')
      assert(result === '12 12th 12')
    })

    it('hour [0-23]', function () {
      var result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'H Ho HH')
      assert(result === '0 0th 00')
    })

    it('hour [0-11]', function () {
      var result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'K Ko KK')
      assert(result === '0 0th 00')
    })

    it('hour [1-24]', function () {
      var result = format(new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0), 'k ko kk')
      assert(result === '24 24th 24')
    })

    describe('AM, PM', function () {
      it('works as expected', function () {
        var result = format(
          new Date(2018, 0 /* Jan */, 1, 0, 0, 0, 0),
          'a aa aaa aaaa aaaaa'
        )
        assert(result === 'AM AM am a.m. a')
      })

      it('12 PM', function () {
        var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900)
        assert(format(date, 'h H K k a') === '12 12 0 12 PM')
      })

      it('12 AM', function () {
        var date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900)
        assert(format(date, 'h H K k a') === '12 0 0 24 AM')
      })
    })

    describe('AM, PM, noon, midnight', function () {
      it('works as expected', function () {
        var result = format(
          new Date(1986, 3 /* Apr */, 6, 2, 0, 0, 900),
          'b bb bbb bbbb bbbbb'
        )
        assert(result === 'AM AM am a.m. a')
      })

      it('12 PM', function () {
        var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900)
        assert(format(date, 'b bb bbb bbbb bbbbb') === 'noon noon noon noon n')
      })

      it('12 AM', function () {
        var date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900)
        assert(
          format(date, 'b bb bbb bbbb bbbbb') ===
            'midnight midnight midnight midnight mi'
        )
      })
    })

    describe('flexible day periods', function () {
      it('works as expected', function () {
        var result = format(date, 'B, BB, BBB, BBBB, BBBBB')
        assert(
          result ===
            'in the morning, in the morning, in the morning, in the morning, in the morning'
        )
      })

      it('12 PM', function () {
        var date = new Date(1986, 3 /* Apr */, 4, 12, 0, 0, 900)
        assert(format(date, 'h B') === '12 in the afternoon')
      })

      it('5 PM', function () {
        var date = new Date(1986, 3 /* Apr */, 6, 17, 0, 0, 900)
        assert(format(date, 'h B') === '5 in the evening')
      })

      it('12 AM', function () {
        var date = new Date(1986, 3 /* Apr */, 6, 0, 0, 0, 900)
        assert(format(date, 'h B') === '12 at night')
      })

      it('4 AM', function () {
        var date = new Date(1986, 3 /* Apr */, 6, 4, 0, 0, 900)
        assert(format(date, 'h B') === '4 in the morning')
      })
    })
  })

  it('minute', function () {
    var result = format(date, 'm mo mm')
    assert(result === '32 32nd 32')
  })

  describe('second', function () {
    it('second', function () {
      var result = format(date, 's so ss')
      assert(result === '55 55th 55')
    })

    it('fractional seconds', function () {
      var result = format(date, 'S SS SSS SSSS')
      assert(result === '1 12 123 1230')
    })
  })

  describe('time zone', function () {
    it('ISO-8601 with Z', function () {
      var result = format(date, 'X XX XXX XXXX XXXXX')
      var expectedResult = [
        timezoneWithOptionalMinutesAndZShort,
        timezoneWithZShort,
        timezoneWithZ,
        timezoneWithZShort,
        timezoneWithZ,
      ].join(' ')
      assert(result === expectedResult)
    })

    it('ISO-8601 without Z', function () {
      var result = format(date, 'x xx xxx xxxx xxxxx')
      var expectedResult = [
        timezoneWithOptionalMinutesShort,
        timezoneShort,
        timezone,
        timezoneShort,
        timezone,
      ].join(' ')
      assert(result === expectedResult)
    })

    it('GMT', function () {
      var result = format(date, 'O OO OOO OOOO')
      var expectedResult = [
        timezoneGMTShort,
        timezoneGMTShort,
        timezoneGMTShort,
        timezoneGMT,
      ].join(' ')
      assert(result === expectedResult)
    })

    it('Specific non-location', function () {
      var result = format(date, 'z zz zzz zzzz')
      var expectedResult = [
        timezoneGMTShort,
        timezoneGMTShort,
        timezoneGMTShort,
        timezoneGMT,
      ].join(' ')
      assert(result === expectedResult)
    })
  })

  describe('timestamp', function () {
    it('seconds timestamp', function () {
      var result = format(date, 't')
      assert(result === secondsTimestamp)
    })

    it('milliseconds timestamp', function () {
      var result = format(date, 'T')
      assert(result === timestamp)
    })
  })

  describe('long format', function () {
    it('short date', function () {
      var result = format(date, 'P')
      assert(result === '04/04/1986')
    })

    it('medium date', function () {
      var result = format(date, 'PP')
      assert(result === 'Apr 4, 1986')
    })

    it('long date', function () {
      var result = format(date, 'PPP')
      assert(result === 'April 4th, 1986')
    })

    it('full date', function () {
      var result = format(date, 'PPPP')
      assert(result === 'Friday, April 4th, 1986')
    })

    it('short time', function () {
      var result = format(date, 'p')
      assert(result === '10:32 AM')
    })

    it('medium time', function () {
      var result = format(date, 'pp')
      assert(result === '10:32:55 AM')
    })

    it('long time', function () {
      var result = format(date, 'ppp')
      assert(result === '10:32:55 AM ' + timezoneGMTShort)
    })

    it('full time', function () {
      var result = format(date, 'pppp')
      assert(result === '10:32:55 AM ' + timezoneGMT)
    })

    it('short date + time', function () {
      var result = format(date, 'Pp')
      assert(result === '04/04/1986, 10:32 AM')
    })

    it('medium date + time', function () {
      var result = format(date, 'PPpp')
      assert(result === 'Apr 4, 1986, 10:32:55 AM')
    })

    it('long date + time', function () {
      var result = format(date, 'PPPppp')
      assert(result === 'April 4th, 1986 at 10:32:55 AM ' + timezoneGMTShort)
    })

    it('full date + time', function () {
      var result = format(date, 'PPPPpppp')
      assert(result === 'Friday, April 4th, 1986 at 10:32:55 AM ' + timezoneGMT)
    })

    it('allows arbitrary combination of date and time', function () {
      var result = format(date, 'Ppppp')
      assert(result === '04/04/1986, 10:32:55 AM ' + timezoneGMT)
    })
  })

  describe('edge cases', function () {
    it('throws RangeError if the time value is invalid', () => {
      assert.throws(
        format.bind(null, new Date(NaN), 'MMMM d, yyyy'),
        RangeError
      )
    })

    it('handles dates before 100 AD', function () {
      var initialDate = new Date(0)
      initialDate.setFullYear(7, 11 /* Dec */, 31)
      initialDate.setHours(0, 0, 0, 0)
      assert(format(initialDate, 'Y ww i') === '8 01 1')
    })
  })

  it('implicitly converts `formatString`', function () {
    // eslint-disable-next-line no-new-wrappers
    var formatString = new String('yyyy-MM-dd')

    var date = new Date(2014, 3, 4)

    // $ExpectedMistake
    assert(format(date, formatString) === '2014-04-04')
  })

  describe('custom locale', function () {
    it('allows to pass a custom locale', function () {
      var customLocale = {
        localize: {
          month: function () {
            return 'works'
          },
        },
        formatLong: {
          date: function () {
            return "'It' MMMM!"
          },
        },
      }
      // $ExpectedMistake
      var result = format(date, 'PPPP', { locale: customLocale })
      assert(result === 'It works!')
    })

    it("throws `RangeError` if `options.locale` doesn't have `localize` property", function () {
      var customLocale = {
        formatLong: {},
      }
      // $ExpectedMistake
      var block = format.bind(null, date, 'yyyy-MM-dd', {
        locale: customLocale,
      })
      assert.throws(block, RangeError)
    })

    it("throws `RangeError` if `options.locale` doesn't have `formatLong` property", function () {
      var customLocale = {
        // $ExpectedMistake
        localize: {},
      }
      // $ExpectedMistake
      var block = format.bind(null, date, 'yyyy-MM-dd', {
        locale: customLocale,
      })
      assert.throws(block, RangeError)
    })
  })

  it('throws `RangeError` if `options.weekStartsOn` is not convertable to 0, 1, ..., 6 or undefined', function () {
    // $ExpectedMistake
    var block = format.bind(null, new Date(2007, 11 /* Dec */, 31), 'yyyy', {
      weekStartsOn: NaN,
    })
    assert.throws(block, RangeError)
  })

  it('throws `RangeError` if `options.firstWeekContainsDate` is not convertable to 1, 2, ..., 7 or undefined', function () {
    // $ExpectedMistake
    var block = format.bind(null, new Date(2007, 11 /* Dec */, 31), 'yyyy', {
      firstWeekContainsDate: NaN,
    })
    assert.throws(block, RangeError)
  })

  it('throws RangeError exception if the format string contains an unescaped latin alphabet character', function () {
    assert.throws(format.bind(null, date, 'yyyy-MM-dd-nnnn'), RangeError)
  })

  it('throws TypeError exception if passed less than 2 arguments', function () {
    assert.throws(format.bind(null), TypeError)
    assert.throws(format.bind(null, 1), TypeError)
  })

  describe('useAdditionalWeekYearTokens and useAdditionalDayOfYearTokens options', () => {
    it('throws an error if D token is used', () => {
      const block = format.bind(null, date, 'yyyy-MM-D')
      assert.throws(block, RangeError)
      assert.throws(
        block,
        /(Use `d` instead of `D` \(in `yyyy-MM-D`\) for formatting days of the month to the input `Fri Apr 04 1986 10:32:55).*(`; see: https:\/\/git.io\/fxCyr)/g
      )
    })

    it('allows D token if useAdditionalDayOfYearTokens is set to true', () => {
      const result = format(date, 'yyyy-MM-D', {
        useAdditionalDayOfYearTokens: true,
      })
      assert.deepEqual(result, '1986-04-94')
    })

    it('throws an error if DD token is used', () => {
      const block = format.bind(null, date, 'yyyy-MM-DD')
      assert.throws(block, RangeError)
      assert.throws(
        block,
        /(Use `dd` instead of `DD` \(in `yyyy-MM-DD`\) for formatting days of the month to the input `Fri Apr 04 1986 10:32:55).*(`; see: https:\/\/git.io\/fxCyr)/g
      )
    })

    it('allows DD token if useAdditionalDayOfYearTokens is set to true', () => {
      const result = format(date, 'yyyy-MM-DD', {
        useAdditionalDayOfYearTokens: true,
      })
      assert.deepEqual(result, '1986-04-94')
    })

    it('throws an error if YY token is used', () => {
      const block = format.bind(null, date, 'YY-MM-dd')
      assert.throws(block, RangeError)
      assert.throws(
        block,
        /(Use `yy` instead of `YY` \(in `YY-MM-dd`\) for formatting years to the input `Fri Apr 04 1986 10:32:55).*(`; see: https:\/\/git.io\/fxCyr)/g
      )
    })

    it('allows YY token if useAdditionalWeekYearTokens is set to true', () => {
      const result = format(date, 'YY-MM-dd', {
        useAdditionalWeekYearTokens: true,
      })
      assert.deepEqual(result, '86-04-04')
    })

    it('throws an error if YYYY token is used', () => {
      const block = format.bind(null, date, 'YYYY-MM-dd')
      assert.throws(block, RangeError)
      assert.throws(
        block,
        /(Use `yyyy` instead of `YYYY` \(in `YYYY-MM-dd`\) for formatting years to the input `Fri Apr 04 1986 10:32:55).*(`; see: https:\/\/git.io\/fxCyr)/g
      )
    })

    it('allows YYYY token if useAdditionalWeekYearTokens is set to true', () => {
      const result = format(date, 'YYYY-MM-dd', {
        useAdditionalWeekYearTokens: true,
      })
      assert.deepEqual(result, '1986-04-04')
    })
  })
})