From 50b2b1f1c2b932b8fa694864755076c66aad5fab Mon Sep 17 00:00:00 2001 From: Jonathan Gilbert Date: Thu, 1 Apr 2021 12:48:18 -0500 Subject: [PATCH] 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. --- Source/Bogus/DataSets/Date.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/Bogus/DataSets/Date.cs b/Source/Bogus/DataSets/Date.cs index d5997b0b..822f6142 100644 --- a/Source/Bogus/DataSets/Date.cs +++ b/Source/Bogus/DataSets/Date.cs @@ -178,12 +178,20 @@ private void ComputeRealRange(ref DateTime start, ref DateTime end) #if !NETSTANDARD1_3 var window = GetForwardDSTTransitionWindow(start); - if ((start > window.Start) && (start <= window.End)) - start = new DateTime(window.End.Ticks, start.Kind); + if ((start >= window.Start) && (start <= window.End)) + { + if ((start == window.Start) && (end >= window.Start) && (end <= window.End)) + end = start; + else + start = new DateTime(window.End.Ticks, start.Kind); + + if (start == end) + return; + } window = GetForwardDSTTransitionWindow(end); - if ((end >= window.Start) && (end < window.End)) + if ((end >= window.Start) && (end <= window.End)) end = new DateTime(window.Start.Ticks, end.Kind); if (start > end)