Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Date data set to avoid DST transition windows #366

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Commits on Apr 21, 2023

  1. Added unit test DateTest.will_not_generate_values_that_do_not_exist_d…

    …ue_to_daylight_savings that detects the error when run in a time zone with DST transitions.
    
    Updated DataSets/Date.cs to funnel all DateTime generation into Between and BetweenOffset, and updated the implementations of Between and BetweenOffset to convert the range to UTC before calculating the random value, and then convert the resulting UTC value back to local time, taking advantage of the framework's automatic DST calculations.
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    18e0cfb View commit details
    Browse the repository at this point in the history
  2. Added tests will_adjust_start_time_to_avoid_dst_transition and will_a…

    …djust_end_time_to_avoid_dst_transition to DateTest.cs.
    
    Added method ComputeRealRange to DataSets/Date.cs, along with helper methods GetForwardDSTTransitionWindow and FindEffectiveTimeZoneAdjustmentRule, to find the windows of time values that don't correspond to real times due to DST transition and adjust the start & end times of the requested time interval to avoid them.
    Rewrote BetweenOffset in DataSets/Date.cs to leverage Between and tack the offset on afterward, so that the avoidance logic need only be in one place.
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    b598ea0 View commit details
    Browse the repository at this point in the history
  3. Added unit tests to DateTest.cs exercising the edge cases where the s…

    …tart/end times are exactly equal to the daylight savings time transition window start/end
    
    Updated ComputeRealRange to detect when start and end are in the same window, and to handle the edge case where start is exactly the last valid date/time before the window.
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    718a240 View commit details
    Browse the repository at this point in the history
  4. Added test DateTest.works_when_start_time_is_invalid_due_to_DST_chang…

    …e_window based on feedback from @bchavez. Updated the CalculateTransitionDateTime helper to specifically mark the DateTimes it returns as being DateTimeKind.Local.
    
    Reworked Date.Between and Date.BetweenOffset to encapsulate the semantics described by the tests:
    - If the range is contained entirely within the forward DST change window (i.e., an empty range), then it will always return the a boundary time. It prefers the end time unless it isn't a real time, in which case it prefers the start time. Updated ComputeRealRange to return out parameter preferRangeBoundary.
    - Updated ComputeRealRange to let the caller indicate whether the DateTime is local or not.
    - Updated BetweenOffset to call ComputeRealRange itself, since the DateTime values going into ComputeRealRange via Between will always be DateTimeKind.Unspecified.
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    41cf3ed View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    bf1ef28 View commit details
    Browse the repository at this point in the history
  6. Updated Recent and RecentOffset to avoid multiple consecutive calls t…

    …o SystemClock, because in extremely rare cases, these could return different values, potentially not even in-order.
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    93edfa9 View commit details
    Browse the repository at this point in the history
  7. Made reference to a variable name in a test failure message dynamical…

    …ly linked to the actual variable using nameof().
    logiclrd authored and bchavez committed Apr 21, 2023
    Configuration menu
    Copy the full SHA
    de19a3b View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    5c6013e View commit details
    Browse the repository at this point in the history