@@ -450,120 +450,145 @@ describe('@mongodb-js/shell-bson-parser', function () {
450
450
}` ;
451
451
452
452
const actual = parse ( input , options ) ;
453
- const expectedDate = new ( Date as any ) ( ...args ) as Date ;
454
453
455
454
// When constructing a date with no arguments, it will be set to the current date,
456
455
// which is prone to race conditions for millisecond precision.
457
456
const allowedMillisecondDelta = args . length === 0 ? 2 : 0 ;
458
457
459
- expect ( actual . getDate ) . to . equal ( expectedDate . getDate ( ) ) ;
460
- expect ( actual . getDay ) . to . equal ( expectedDate . getDay ( ) ) ;
461
- expect ( actual . getFullYear ) . to . equal ( expectedDate . getFullYear ( ) ) ;
462
- expect ( actual . getHours ) . to . equal ( expectedDate . getHours ( ) ) ;
458
+ expect ( actual . getDate ) . to . equal (
459
+ new ( Date as any ) ( ...args ) . getDate ( )
460
+ ) ;
461
+ expect ( actual . getDay ) . to . equal (
462
+ new ( Date as any ) ( ...args ) . getDay ( )
463
+ ) ;
464
+ expect ( actual . getFullYear ) . to . equal (
465
+ new ( Date as any ) ( ...args ) . getFullYear ( )
466
+ ) ;
467
+ expect ( actual . getHours ) . to . equal (
468
+ new ( Date as any ) ( ...args ) . getHours ( )
469
+ ) ;
463
470
expect ( actual . getMilliseconds ) . to . be . approximately (
464
- expectedDate . getMilliseconds ( ) ,
471
+ new ( Date as any ) ( ... args ) . getMilliseconds ( ) ,
465
472
allowedMillisecondDelta
466
473
) ;
467
- expect ( actual . getMinutes ) . to . equal ( expectedDate . getMinutes ( ) ) ;
468
- expect ( actual . getMonth ) . to . equal ( expectedDate . getMonth ( ) ) ;
469
- expect ( actual . getSeconds ) . to . equal ( expectedDate . getSeconds ( ) ) ;
474
+ expect ( actual . getMinutes ) . to . equal (
475
+ new ( Date as any ) ( ...args ) . getMinutes ( )
476
+ ) ;
477
+ expect ( actual . getMonth ) . to . equal (
478
+ new ( Date as any ) ( ...args ) . getMonth ( )
479
+ ) ;
480
+ expect ( actual . getSeconds ) . to . equal (
481
+ new ( Date as any ) ( ...args ) . getSeconds ( )
482
+ ) ;
470
483
expect ( actual . getTime ) . to . be . approximately (
471
- expectedDate . getTime ( ) ,
484
+ new ( Date as any ) ( ... args ) . getTime ( ) ,
472
485
allowedMillisecondDelta
473
486
) ;
474
487
expect ( actual . getTimezoneOffset ) . to . equal (
475
- expectedDate . getTimezoneOffset ( )
488
+ new ( Date as any ) ( ...args ) . getTimezoneOffset ( )
489
+ ) ;
490
+ expect ( actual . getUTCDate ) . to . equal (
491
+ new ( Date as any ) ( ...args ) . getUTCDate ( )
492
+ ) ;
493
+ expect ( actual . getUTCDay ) . to . equal (
494
+ new ( Date as any ) ( ...args ) . getUTCDay ( )
476
495
) ;
477
- expect ( actual . getUTCDate ) . to . equal ( expectedDate . getUTCDate ( ) ) ;
478
- expect ( actual . getUTCDay ) . to . equal ( expectedDate . getUTCDay ( ) ) ;
479
496
expect ( actual . getUTCFullYear ) . to . equal (
480
- expectedDate . getUTCFullYear ( )
497
+ new ( Date as any ) ( ...args ) . getUTCFullYear ( )
498
+ ) ;
499
+ expect ( actual . getUTCHours ) . to . equal (
500
+ new ( Date as any ) ( ...args ) . getUTCHours ( )
481
501
) ;
482
- expect ( actual . getUTCHours ) . to . equal ( expectedDate . getUTCHours ( ) ) ;
483
502
expect ( actual . getUTCMilliseconds ) . to . be . approximately (
484
- expectedDate . getUTCMilliseconds ( ) ,
503
+ new ( Date as any ) ( ... args ) . getUTCMilliseconds ( ) ,
485
504
allowedMillisecondDelta
486
505
) ;
487
506
expect ( actual . getUTCMinutes ) . to . equal (
488
- expectedDate . getUTCMinutes ( )
507
+ new ( Date as any ) ( ...args ) . getUTCMinutes ( )
508
+ ) ;
509
+ expect ( actual . getUTCMonth ) . to . equal (
510
+ new ( Date as any ) ( ...args ) . getUTCMonth ( )
489
511
) ;
490
- expect ( actual . getUTCMonth ) . to . equal ( expectedDate . getUTCMonth ( ) ) ;
491
512
expect ( actual . getUTCSeconds ) . to . equal (
492
- expectedDate . getUTCSeconds ( )
513
+ new ( Date as any ) ( ... args ) . getUTCSeconds ( )
493
514
) ;
494
- expect ( actual . getYear ) . to . equal ( ( expectedDate as any ) . getYear ( ) ) ; // getYear is deprecated
515
+ expect ( actual . getYear ) . to . equal (
516
+ ( new ( Date as any ) ( ...args ) as any ) . getYear ( )
517
+ ) ; // getYear is deprecated
495
518
expect ( actual . setDate ) . to . be . approximately (
496
- new Date ( expectedDate ) . setDate ( 24 ) ,
519
+ new ( Date as any ) ( ... args ) . setDate ( 24 ) ,
497
520
allowedMillisecondDelta
498
521
) ;
499
522
expect ( actual . setFullYear ) . to . be . approximately (
500
- new Date ( expectedDate ) . setFullYear ( 2010 ) ,
523
+ new ( Date as any ) ( ... args ) . setFullYear ( 2010 ) ,
501
524
allowedMillisecondDelta
502
525
) ;
503
526
expect ( actual . setHours ) . to . be . approximately (
504
- new Date ( expectedDate ) . setHours ( 23 ) ,
527
+ new ( Date as any ) ( ... args ) . setHours ( 23 ) ,
505
528
allowedMillisecondDelta
506
529
) ;
507
530
expect ( actual . setMilliseconds ) . to . be . approximately (
508
- new Date ( expectedDate ) . setMilliseconds ( 1 ) ,
531
+ new ( Date as any ) ( ... args ) . setMilliseconds ( 1 ) ,
509
532
allowedMillisecondDelta
510
533
) ;
511
534
expect ( actual . setMinutes ) . to . be . approximately (
512
- new Date ( expectedDate ) . setMinutes ( 1 ) ,
535
+ new ( Date as any ) ( ... args ) . setMinutes ( 1 ) ,
513
536
allowedMillisecondDelta
514
537
) ;
515
538
expect ( actual . setMonth ) . to . be . approximately (
516
- new Date ( expectedDate ) . setMonth ( 1 ) ,
539
+ new ( Date as any ) ( ... args ) . setMonth ( 1 ) ,
517
540
allowedMillisecondDelta
518
541
) ;
519
542
expect ( actual . setSeconds ) . to . be . approximately (
520
- new Date ( expectedDate ) . setSeconds ( 59 ) ,
543
+ new ( Date as any ) ( ... args ) . setSeconds ( 59 ) ,
521
544
allowedMillisecondDelta
522
545
) ;
523
546
expect ( actual . setTime ) . to . be . approximately (
524
- new Date ( expectedDate ) . setTime ( 10 ) ,
547
+ new ( Date as any ) ( ... args ) . setTime ( 10 ) ,
525
548
allowedMillisecondDelta
526
549
) ;
527
550
expect ( actual . setUTCDate ) . to . be . approximately (
528
- new Date ( expectedDate ) . setUTCDate ( 24 ) ,
551
+ new ( Date as any ) ( ... args ) . setUTCDate ( 24 ) ,
529
552
allowedMillisecondDelta
530
553
) ;
531
554
expect ( actual . setUTCFullYear ) . to . be . approximately (
532
- new Date ( expectedDate ) . setUTCFullYear ( 2010 ) ,
555
+ new ( Date as any ) ( ... args ) . setUTCFullYear ( 2010 ) ,
533
556
allowedMillisecondDelta
534
557
) ;
535
558
expect ( actual . setUTCHours ) . to . be . approximately (
536
- new Date ( expectedDate ) . setUTCHours ( 23 ) ,
559
+ new ( Date as any ) ( ... args ) . setUTCHours ( 23 ) ,
537
560
allowedMillisecondDelta
538
561
) ;
539
562
expect ( actual . setUTCMilliseconds ) . to . be . approximately (
540
- new Date ( expectedDate ) . setUTCMilliseconds ( 1 ) ,
563
+ new ( Date as any ) ( ... args ) . setUTCMilliseconds ( 1 ) ,
541
564
allowedMillisecondDelta
542
565
) ;
543
566
expect ( actual . setUTCMinutes ) . to . be . approximately (
544
- new Date ( expectedDate ) . setUTCMinutes ( 1 ) ,
567
+ new ( Date as any ) ( ... args ) . setUTCMinutes ( 1 ) ,
545
568
allowedMillisecondDelta
546
569
) ;
547
570
expect ( actual . setUTCMonth ) . to . be . approximately (
548
- new Date ( expectedDate ) . setUTCMonth ( 1 ) ,
571
+ new ( Date as any ) ( ... args ) . setUTCMonth ( 1 ) ,
549
572
allowedMillisecondDelta
550
573
) ;
551
574
expect ( actual . setUTCSeconds ) . to . be . approximately (
552
- new Date ( expectedDate ) . setUTCSeconds ( 59 ) ,
575
+ new ( Date as any ) ( ... args ) . setUTCSeconds ( 59 ) ,
553
576
allowedMillisecondDelta
554
577
) ;
555
578
expect ( actual . setYear ) . to . be . approximately (
556
- ( new Date ( expectedDate ) as any ) . setYear ( 96 ) ,
579
+ ( new ( Date as any ) ( ... args ) as any ) . setYear ( 96 ) ,
557
580
allowedMillisecondDelta
558
581
) ; // setYear is deprecated
559
582
expect ( actual . valueOf ) . to . be . approximately (
560
- expectedDate . valueOf ( ) ,
583
+ new ( Date as any ) ( ... args ) . valueOf ( ) ,
561
584
allowedMillisecondDelta
562
585
) ;
563
586
564
587
const isoRegex = / ^ ( [ ^ . ] * \. ) ( [ \d ] * ) ( Z ) $ / ;
565
588
const actualMatch = isoRegex . exec ( actual . toISOString ) ;
566
- const expectedMatch = isoRegex . exec ( expectedDate . toISOString ( ) ) ;
589
+ const expectedMatch = isoRegex . exec (
590
+ new ( Date as any ) ( ...args ) . toISOString ( )
591
+ ) ;
567
592
568
593
expect ( actualMatch ?. length ) . to . equal ( 4 ) ;
569
594
expect ( expectedMatch ?. length ) . to . equal ( 4 ) ;
0 commit comments