Skip to content

Commit

Permalink
Update DateScrubber.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 30, 2024
1 parent d1f7031 commit efee867
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/Verify/Serialization/Scrubbers/DateScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ delegate bool TryConvert(
Culture culture,
[NotNullWhen(true)] out string? result);

static IReadOnlyDictionary<string, string> expands = new Dictionary<string, string>
{
{"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<string, string> expands = new Dictionary<string, string>
// {
// {"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

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit efee867

Please sign in to comment.