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 29, 2024
1 parent 7308cb7 commit 6dbd88c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Verify/Serialization/Scrubbers/DateScrubber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ static bool TryConvertDate(
Culture culture,
[NotNullWhen(true)] out string? result)
{
if (span.ContainsNewline())
{
result = null;
return false;
}

if (Date.TryParseExact(span, format, culture, DateTimeStyles.None, out var date))
{
result = SerializationSettings.Convert(counter, date);
Expand Down Expand Up @@ -80,6 +86,12 @@ static bool TryConvertDateTimeOffset(
Culture culture,
[NotNullWhen(true)] out string? result)
{
if (span.ContainsNewline())
{
result = null;
return false;
}

if (DateTimeOffsetPolyfill.TryParseExact(span, format, culture, DateTimeStyles.None, out var date))
{
result = SerializationSettings.Convert(counter, date);
Expand Down Expand Up @@ -110,6 +122,12 @@ static bool TryConvertDateTime(
Culture culture,
[NotNullWhen(true)] out string? result)
{
if (span.ContainsNewline())
{
result = null;
return false;
}

if (DateTimePolyfill.TryParseExact(span, format, culture, DateTimeStyles.None, out var date))
{
result = SerializationSettings.Convert(counter, date);
Expand Down Expand Up @@ -176,8 +194,7 @@ int Length(DateTime dateTime)
}

var slice = value.Slice(index, length);
if (!slice.ContainsNewline() &&
tryConvertDate(slice, format, counter, culture, out var convert))
if (tryConvertDate(slice, format, counter, culture, out var convert))
{
builder.Overwrite(convert, builderIndex, length);
builderIndex += convert.Length;
Expand Down

0 comments on commit 6dbd88c

Please sign in to comment.