@@ -460,6 +460,90 @@ public void will_adjust_end_time_to_avoid_dst_transition()
460
460
}
461
461
}
462
462
463
+ [ FactWhenDaylightSavingsSupported ]
464
+ public void works_when_range_is_exactly_daylight_savings_transition_window ( )
465
+ {
466
+ // Arrange
467
+ var faker = new Faker ( ) ;
468
+
469
+ faker . Random = new Randomizer ( localSeed : 5 ) ;
470
+
471
+ var dstRules = TimeZoneInfo . Local . GetAdjustmentRules ( ) ;
472
+
473
+ var now = DateTime . Now ;
474
+
475
+ var effectiveRule = dstRules . Single ( rule => ( rule . DateStart <= now ) && ( rule . DateEnd >= now ) ) ;
476
+
477
+ var transitionStartTime = CalculateTransitionDateTime ( now , effectiveRule . DaylightTransitionStart ) ;
478
+ var transitionEndTime = transitionStartTime + effectiveRule . DaylightDelta ;
479
+
480
+ // Act & Assert
481
+ for ( int i = 0 ; i < 10000 ; i ++ )
482
+ {
483
+ var sample = faker . Date . Between ( transitionStartTime , transitionEndTime ) ;
484
+
485
+ sample . Should ( ) . BeOneOf ( transitionStartTime , transitionEndTime ) ;
486
+ }
487
+ }
488
+
489
+ [ FactWhenDaylightSavingsSupported ]
490
+ public void works_when_range_start_is_exactly_daylight_savings_transition_window_start ( )
491
+ {
492
+ // Arrange
493
+ var faker = new Faker ( ) ;
494
+
495
+ faker . Random = new Randomizer ( localSeed : 5 ) ;
496
+
497
+ var dstRules = TimeZoneInfo . Local . GetAdjustmentRules ( ) ;
498
+
499
+ var now = DateTime . Now ;
500
+
501
+ var effectiveRule = dstRules . Single ( rule => ( rule . DateStart <= now ) && ( rule . DateEnd >= now ) ) ;
502
+
503
+ var transitionStartTime = CalculateTransitionDateTime ( now , effectiveRule . DaylightTransitionStart ) ;
504
+ var transitionEndTime = transitionStartTime + effectiveRule . DaylightDelta ;
505
+
506
+ var windowStart = transitionStartTime ;
507
+ var windowEnd = transitionEndTime . AddMinutes ( - 5 ) ;
508
+
509
+ // Act & Assert
510
+ for ( int i = 0 ; i < 10000 ; i ++ )
511
+ {
512
+ var sample = faker . Date . Between ( windowStart , windowEnd ) ;
513
+
514
+ sample . Should ( ) . Be ( windowStart ) ;
515
+ }
516
+ }
517
+
518
+ [ FactWhenDaylightSavingsSupported ]
519
+ public void works_when_range_end_is_exactly_daylight_savings_transition_window_end ( )
520
+ {
521
+ // Arrange
522
+ var faker = new Faker ( ) ;
523
+
524
+ faker . Random = new Randomizer ( localSeed : 5 ) ;
525
+
526
+ var dstRules = TimeZoneInfo . Local . GetAdjustmentRules ( ) ;
527
+
528
+ var now = DateTime . Now ;
529
+
530
+ var effectiveRule = dstRules . Single ( rule => ( rule . DateStart <= now ) && ( rule . DateEnd >= now ) ) ;
531
+
532
+ var transitionStartTime = CalculateTransitionDateTime ( now , effectiveRule . DaylightTransitionStart ) ;
533
+ var transitionEndTime = transitionStartTime + effectiveRule . DaylightDelta ;
534
+
535
+ var windowStart = transitionStartTime . AddMinutes ( 5 ) ;
536
+ var windowEnd = transitionEndTime ;
537
+
538
+ // Act & Assert
539
+ for ( int i = 0 ; i < 10000 ; i ++ )
540
+ {
541
+ var sample = faker . Date . Between ( windowStart , windowEnd ) ;
542
+
543
+ sample . Should ( ) . Be ( windowEnd ) ;
544
+ }
545
+ }
546
+
463
547
private DateTime CalculateTransitionDateTime ( DateTime now , TimeZoneInfo . TransitionTime transition )
464
548
{
465
549
// Based on code found at: https://docs.microsoft.com/en-us/dotnet/api/system.timezoneinfo.transitiontime.isfixeddaterule
0 commit comments