Skip to content

Commit

Permalink
Add parsing of roundtrip time without milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-ciechan committed Oct 18, 2024
1 parent 269bbd3 commit 473a61e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions MikeysUtils3.UnitTests/DateTimeParsingSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ public async Task DateIntDoubleDigitYear()
"""
);
}

[Test]
public async Task RoundtripStandard_NoMilliSeconds()
{
var input = "2024-10-16T17:03:43Z";

var results = Parse(input);

InlineSnapshot.Validate(
results,
"""
- DateTimeType: DateTime_UTC_ISO_8601
ParsedDateTime: 2024-10-16T17:03:43.0000000Z
Kind: Utc
"""
);
}

private static List<Result> Parse(string input)
{
Expand Down
6 changes: 4 additions & 2 deletions MikeysUtils3/Pages/DateTimePage/DateTimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ out dateTimeParsed
);
case DateTimeType.DateTime_UTC_ISO_8601:
return DateTime.TryParseExact(
input, "O", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None,
out dateTimeParsed);
input, "O", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None,
out dateTimeParsed) ||
DateTime.TryParseExact(input, "yyyy-MM-ddTHH:mm:ssZ", DateTimeFormatInfo.InvariantInfo,
DateTimeStyles.AdjustToUniversal, out dateTimeParsed);
case DateTimeType.DateTime_UTC_RFC_1123:
return DateTime.TryParseExact(
input, "R", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None,
Expand Down

0 comments on commit 473a61e

Please sign in to comment.