Skip to content

Commit dedd936

Browse files
author
Maksim Golev
committed
fix(#51740): Adding comma as valid time fraction delimiter.
1 parent 2e50919 commit dedd936

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal static class DateTimeParse
1414
internal const int MaxDateTimeNumberDigits = 8;
1515

1616
internal const char TimeDelimiter = ':';
17+
internal const char TimeFractionDelimiterComma = ',';
1718
internal const char TimeFractionDelimiterDot = '.';
1819

1920
internal static DateTime ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, DateTimeFormatInfo dtfi, DateTimeStyles style)
@@ -645,7 +646,8 @@ private static bool Lex(DS dps, ref __DTString str, scoped ref DateTimeToken dto
645646
if (str.Index < str.Length - 1)
646647
{
647648
char nextCh = str.Value[str.Index];
648-
if (nextCh == TimeFractionDelimiterDot)
649+
if ((nextCh == TimeFractionDelimiterDot)
650+
|| (nextCh == TimeFractionDelimiterComma))
649651
{
650652
// While ParseFraction can fail, it just means that there were no digits after
651653
// the dot. In this case ParseFraction just removes the dot. This is actually
@@ -2984,7 +2986,8 @@ private static bool ParseISO8601(scoped ref DateTimeRawInfo raw, ref __DTString
29842986
result.SetBadDateTimeFailure();
29852987
return false;
29862988
}
2987-
if (str.Match(TimeFractionDelimiterDot))
2989+
if ((str.Match(TimeFractionDelimiterDot))
2990+
|| (str.Match(TimeFractionDelimiterComma)))
29882991
{
29892992
if (!ParseFraction(ref str, out partSecond))
29902993
{

src/libraries/System.Runtime/tests/System/DateTimeOffsetTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,18 @@ public static void Compare(DateTimeOffset dateTimeOffset1, DateTimeOffset dateTi
856856
}
857857
}
858858

859-
[Fact]
860-
public static void Parse_String()
859+
public static IEnumerable<object[]> Parse_TestData()
861860
{
862-
DateTimeOffset expected = DateTimeOffset.MaxValue;
863-
string expectedString = expected.ToString();
861+
yield return new object[] { "2021-04-23T13:04:17,307642270+02:00", new DateTimeOffset(637547798573076423, new TimeSpan(2, 0, 0)) };
862+
yield return new object[] { DateTimeOffset.MaxValue.ToString("O"), DateTimeOffset.MaxValue };
863+
}
864864

865-
DateTimeOffset result = DateTimeOffset.Parse(expectedString);
866-
Assert.Equal(expectedString, result.ToString());
865+
[Theory]
866+
[MemberData(nameof(Parse_TestData))]
867+
public static void Parse_String(string valueForParse, DateTimeOffset expectedValue)
868+
{
869+
DateTimeOffset actualValue = DateTimeOffset.Parse(valueForParse);
870+
Assert.Equal(expectedValue, actualValue);
867871
}
868872

869873
[Fact]

0 commit comments

Comments
 (0)