@@ -17,6 +17,11 @@ test('bounds can be swapped', () => {
17
17
expect ( dayjs ( '2018-01-01' ) . isBetween ( dayjs ( '2018-01-02' ) , dayjs ( '2017-12-31' ) ) ) . toBeTruthy ( )
18
18
} )
19
19
20
+ test ( 'bounds can be swapped with inclusivity' , ( ) => {
21
+ expect ( dayjs ( '2018-01-01' ) . isBetween ( dayjs ( '2017-12-31' ) , dayjs ( '2018-01-01' ) , null , '[]' ) ) . toBeTruthy ( )
22
+ expect ( dayjs ( '2018-01-01' ) . isBetween ( dayjs ( '2018-01-01' ) , dayjs ( '2017-12-31' ) , null , '[]' ) ) . toBeTruthy ( )
23
+ } )
24
+
20
25
test ( 'is between without units' , ( ) => {
21
26
const m = dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) )
22
27
const mCopy = dayjs ( m )
@@ -381,3 +386,303 @@ test('is between millisecond', () => {
381
386
expect ( m . isBetween ( m , 'millisecond' ) ) . toBe ( false , 'same moments are not between the same millisecond' )
382
387
expect ( + m ) . toEqual ( + mCopy , 'isBetween millisecond should not change moment' )
383
388
} )
389
+
390
+ test ( 'is between without units inclusivity' , ( ) => {
391
+ const m = dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) )
392
+ const mCopy = dayjs ( m )
393
+
394
+ expect ( m . isBetween (
395
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
396
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
397
+ null ,
398
+ '()'
399
+ ) ) . toBe ( false , 'start and end are excluded, start is equal to dayjs' )
400
+
401
+ expect ( m . isBetween (
402
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
403
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
404
+ null ,
405
+ '()'
406
+ ) ) . toBe ( false , 'start and end are excluded, end is equal to dayjs' )
407
+
408
+ expect ( m . isBetween (
409
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
410
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
411
+ null ,
412
+ '()'
413
+ ) ) . toBe ( true , 'start and end are excluded, is between' )
414
+
415
+ expect ( m . isBetween (
416
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
417
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
418
+ null ,
419
+ '()'
420
+ ) ) . toBe ( false , 'start and end are excluded, is not between' )
421
+
422
+ expect ( m . isBetween (
423
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
424
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
425
+ null ,
426
+ '()'
427
+ ) ) . toBe ( false , 'start and end are excluded, should fail on same start/end date.' )
428
+
429
+ expect ( m . isBetween (
430
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
431
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
432
+ null ,
433
+ '(]'
434
+ ) ) . toBe ( false , 'start is excluded and end is included should fail on same start date' )
435
+
436
+ expect ( m . isBetween (
437
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
438
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
439
+ null ,
440
+ '(]'
441
+ ) ) . toBe ( true , 'start is excluded and end is included should succeed on end date' )
442
+
443
+ expect ( m . isBetween (
444
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
445
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
446
+ null ,
447
+ '(]'
448
+ ) ) . toBe ( true , 'start is excluded and end is included, is between' )
449
+
450
+ expect ( m . isBetween (
451
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
452
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
453
+ null ,
454
+ '(]'
455
+ ) ) . toBe ( false , 'start is excluded and end is included, is not between' )
456
+
457
+ expect ( m . isBetween (
458
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
459
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
460
+ null ,
461
+ '(]'
462
+ ) ) . toBe ( false , 'start is excluded and end is included, should fail on same start/end date.' )
463
+
464
+ expect ( m . isBetween (
465
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
466
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
467
+ null ,
468
+ '[)'
469
+ ) ) . toBe ( true , 'start is included and end is excluded should succeed on same start date' )
470
+
471
+ expect ( m . isBetween (
472
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
473
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
474
+ null ,
475
+ '[)'
476
+ ) ) . toBe ( false , 'start is included and end is excluded should fail on same end date' )
477
+
478
+ expect ( m . isBetween (
479
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
480
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
481
+ null ,
482
+ '[)'
483
+ ) ) . toBe ( true , 'start is included and end is excluded, is between' )
484
+
485
+ expect ( m . isBetween (
486
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
487
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
488
+ null ,
489
+ '[)'
490
+ ) ) . toBe ( false , 'start is included and end is excluded, is not between' )
491
+
492
+ expect ( m . isBetween (
493
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
494
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
495
+ null ,
496
+ '[)'
497
+ ) ) . toBe ( false , 'start is included and end is excluded, should fail on same end and start date' )
498
+
499
+ expect ( m . isBetween (
500
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
501
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
502
+ null ,
503
+ '[]'
504
+ ) ) . toBe ( true , 'start and end inclusive should succeed on same start date' )
505
+
506
+ expect ( m . isBetween (
507
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
508
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
509
+ null ,
510
+ '[]'
511
+ ) ) . toBe ( true , 'start and end inclusive should succeed on same end date' )
512
+
513
+ expect ( m . isBetween (
514
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
515
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
516
+ null ,
517
+ '[]'
518
+ ) ) . toBe ( true , 'start and end inclusive, is between' )
519
+
520
+ expect ( m . isBetween (
521
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
522
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
523
+ null ,
524
+ '[]'
525
+ ) ) . toBe ( false , 'start and end inclusive, is not between' )
526
+
527
+ expect ( m . isBetween (
528
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
529
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
530
+ null ,
531
+ '[]'
532
+ ) ) . toBe ( true , 'start and end inclusive, should handle same end and start date' )
533
+
534
+ expect ( + m ) . toEqual ( + mCopy , 'isBetween millisecond should not change moment' )
535
+ } )
536
+
537
+ test ( 'is between milliseconds inclusivity' , ( ) => {
538
+ const m = dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) )
539
+ const mCopy = dayjs ( m )
540
+
541
+ expect ( m . isBetween (
542
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
543
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
544
+ 'milliseconds'
545
+ ) ) . toBe ( true , 'options, no inclusive' )
546
+
547
+ expect ( m . isBetween (
548
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
549
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
550
+ 'milliseconds' ,
551
+ '()'
552
+ ) ) . toBe ( false , 'start and end are excluded, start is equal to dayjs' )
553
+
554
+ expect ( m . isBetween (
555
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
556
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
557
+ 'milliseconds' ,
558
+ '()'
559
+ ) ) . toBe ( false , 'start and end are excluded, end is equal to dayjs' )
560
+
561
+ expect ( m . isBetween (
562
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
563
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
564
+ 'milliseconds' ,
565
+ '()'
566
+ ) ) . toBe ( true , 'start and end are excluded, is between' )
567
+
568
+ expect ( m . isBetween (
569
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
570
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
571
+ 'milliseconds' ,
572
+ '()'
573
+ ) ) . toBe ( false , 'start and end are excluded, is not between' )
574
+
575
+ expect ( m . isBetween (
576
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
577
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
578
+ 'milliseconds' ,
579
+ '()'
580
+ ) ) . toBe ( false , 'start and end are excluded, should fail on same start/end date.' )
581
+
582
+ expect ( m . isBetween (
583
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
584
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
585
+ 'milliseconds' ,
586
+ '(]'
587
+ ) ) . toBe ( false , 'start is excluded and end is included should fail on same start date' )
588
+
589
+ expect ( m . isBetween (
590
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
591
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
592
+ 'milliseconds' ,
593
+ '(]'
594
+ ) ) . toBe ( true , 'start is excluded and end is included should succeed on end date' )
595
+
596
+ expect ( m . isBetween (
597
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
598
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
599
+ 'milliseconds' ,
600
+ '(]'
601
+ ) ) . toBe ( true , 'start is excluded and end is included, is between' )
602
+
603
+ expect ( m . isBetween (
604
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
605
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
606
+ 'milliseconds' ,
607
+ '(]'
608
+ ) ) . toBe ( false , 'start is excluded and end is included, is not between' )
609
+
610
+ expect ( m . isBetween (
611
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
612
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
613
+ 'milliseconds' ,
614
+ '(]'
615
+ ) ) . toBe ( false , 'start is excluded and end is included, should fail on same start/end date.' )
616
+
617
+ expect ( m . isBetween (
618
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
619
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
620
+ 'milliseconds' ,
621
+ '[)'
622
+ ) ) . toBe ( true , 'start is included and end is excluded should succeed on same start date' )
623
+
624
+ expect ( m . isBetween (
625
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
626
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
627
+ 'milliseconds' ,
628
+ '[)'
629
+ ) ) . toBe ( false , 'start is included and end is excluded should fail on same end date' )
630
+
631
+ expect ( m . isBetween (
632
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
633
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
634
+ 'milliseconds' ,
635
+ '[)'
636
+ ) ) . toBe ( true , 'start is included and end is excluded, is between' )
637
+
638
+ expect ( m . isBetween (
639
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
640
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
641
+ 'milliseconds' ,
642
+ '[)'
643
+ ) ) . toBe ( false , 'start is included and end is excluded, is not between' )
644
+
645
+ expect ( m . isBetween (
646
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
647
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
648
+ 'milliseconds' ,
649
+ '[)'
650
+ ) ) . toBe ( false , 'start is included and end is excluded, should fail on same end and start date' )
651
+
652
+ expect ( m . isBetween (
653
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
654
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
655
+ 'milliseconds' ,
656
+ '[]'
657
+ ) ) . toBe ( true , 'start and end inclusive should succeed on same start date' )
658
+
659
+ expect ( m . isBetween (
660
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
661
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
662
+ 'milliseconds' ,
663
+ '[]'
664
+ ) ) . toBe ( true , 'start and end inclusive should succeed on same end date' )
665
+
666
+ expect ( m . isBetween (
667
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
668
+ dayjs ( new Date ( 2012 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
669
+ 'milliseconds' ,
670
+ '[]'
671
+ ) ) . toBe ( true , 'start and end inclusive, is between' )
672
+
673
+ expect ( m . isBetween (
674
+ dayjs ( new Date ( 2009 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
675
+ dayjs ( new Date ( 2010 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
676
+ 'milliseconds' ,
677
+ '[]'
678
+ ) ) . toBe ( false , 'start and end inclusive, is not between' )
679
+
680
+ expect ( m . isBetween (
681
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
682
+ dayjs ( new Date ( 2011 , 3 , 2 , 3 , 4 , 5 , 10 ) ) ,
683
+ 'milliseconds' ,
684
+ '[]'
685
+ ) ) . toBe ( true , 'start and end inclusive, should handle same end and start date' )
686
+
687
+ expect ( + m ) . toEqual ( + mCopy , 'isBetween second should not change moment' )
688
+ } )
0 commit comments