From efee867ef9285d7af76ad9f2296e91895b782b6d Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 30 Dec 2024 19:49:53 +1100 Subject: [PATCH] Update DateScrubber.cs --- .../Serialization/Scrubbers/DateScrubber.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Verify/Serialization/Scrubbers/DateScrubber.cs b/src/Verify/Serialization/Scrubbers/DateScrubber.cs index e37670564..7fe833def 100644 --- a/src/Verify/Serialization/Scrubbers/DateScrubber.cs +++ b/src/Verify/Serialization/Scrubbers/DateScrubber.cs @@ -8,20 +8,20 @@ delegate bool TryConvert( Culture culture, [NotNullWhen(true)] out string? result); - static IReadOnlyDictionary expands = new Dictionary - { - {"d", "MM/dd/yyyy"}, - {"D", "dddd, dd MMMM yyyy"}, - {"g", "MM/dd/yyyy HH:mm"}, - {"G", "MM/dd/yyyy HH:mm:ss"}, - {"O", "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK"}, - {"r", "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"}, - {"R", "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"}, - {"u", "yyyy'-'MM'-'dd'T'HH':'mm':'ss"}, - {"s", "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"}, - {"F", "dddd, dd MMMM yyyy HH:mm:ss"}, - {"U", "dddd, dd MMMM yyyy HH:mm:ss"}, - }.ToFrozenDictionary(); + // static IReadOnlyDictionary expands = new Dictionary + // { + // {"d", "MM/dd/yyyy"}, + // {"D", "dddd, dd MMMM yyyy"}, + // {"g", "MM/dd/yyyy HH:mm"}, + // {"G", "MM/dd/yyyy HH:mm:ss"}, + // {"O", "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK"}, + // {"r", "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"}, + // {"R", "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"}, + // {"u", "yyyy'-'MM'-'dd'T'HH':'mm':'ss"}, + // {"s", "yyyy'-'MM'-'dd HH':'mm':'ss'Z'"}, + // {"F", "dddd, dd MMMM yyyy HH:mm:ss"}, + // {"U", "dddd, dd MMMM yyyy HH:mm:ss"}, + // }.ToFrozenDictionary(); #if NET6_0_OR_GREATER @@ -192,14 +192,19 @@ int Length(DateTime dateTime) } var cultureDate = GetCultureDates(culture); - var value = builder.AsSpan(); var shortest = Length(cultureDate.Short); + if (builder.Length < shortest) + { + return; + } + var longest = Length(cultureDate.Long); + var value = builder.AsSpan(); var builderIndex = 0; if (shortest == longest) { - for (var index = 0; index <= value.Length-longest; index++) + for (var index = 0; index <= value.Length - longest; index++) { var slice = value.Slice(index, longest); if (tryConvertDate(slice, format, counter, culture, out var convert))