Skip to content

Commit 4848f51

Browse files
issue-46477 Fix issue about checking last char in datetime string. (#46614)
* issue-46477 Fix issue about checking last char in datetime string. * issue-46477 Fix comment: Add more tests with timezone part.
1 parent 49a83ae commit 4848f51

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,6 +3002,7 @@ private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, Da
30023002
result.SetBadDateTimeFailure();
30033003
return false;
30043004
}
3005+
str.Index--;
30053006
}
30063007
else if (ch == 'Z' || ch == 'z')
30073008
{

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,18 @@ public static void Parse_InvalidArguments_Throws()
10411041
Assert.Throws<FormatException>(() => DateTime.Parse(""));
10421042
Assert.Throws<FormatException>(() => DateTime.Parse("", new MyFormatter()));
10431043
Assert.Throws<FormatException>(() => DateTime.Parse("", new MyFormatter(), DateTimeStyles.NoCurrentDateDefault));
1044+
1045+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000-07:00c"));
1046+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000-07:00c", new MyFormatter()));
1047+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000-07:00c", new MyFormatter(), DateTimeStyles.NoCurrentDateDefault));
1048+
1049+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#"));
1050+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#", new MyFormatter()));
1051+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#", new MyFormatter(), DateTimeStyles.NoCurrentDateDefault));
1052+
1053+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#\0"));
1054+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#\0", new MyFormatter()));
1055+
Assert.Throws<FormatException>(() => DateTime.Parse("2020-5-7T09:37:00.0000000+00:00#\0", new MyFormatter(), DateTimeStyles.NoCurrentDateDefault));
10441056
}
10451057

10461058
[Theory]
@@ -1711,6 +1723,11 @@ public static IEnumerable<object[]> Parse_ValidInput_Succeeds_MemberData()
17111723
yield return new object[] { "2 2 2Z", CultureInfo.InvariantCulture, TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2002, 2, 2, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local) };
17121724
yield return new object[] { "#10/10/2095#\0", CultureInfo.InvariantCulture, new DateTime(2095, 10, 10, 0, 0, 0) };
17131725

1726+
yield return new object[] { "2020-5-7T09:37:00.0000000+00:00\0", CultureInfo.InvariantCulture, TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2020, 5, 7, 9, 37, 0, DateTimeKind.Utc), TimeZoneInfo.Local) };
1727+
yield return new object[] { "#2020-5-7T09:37:00.0000000+00:00#", CultureInfo.InvariantCulture, TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2020, 5, 7, 9, 37, 0, DateTimeKind.Utc), TimeZoneInfo.Local) };
1728+
yield return new object[] { "#2020-5-7T09:37:00.0000000+00:00#\0", CultureInfo.InvariantCulture, TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2020, 5, 7, 9, 37, 0, DateTimeKind.Utc), TimeZoneInfo.Local) };
1729+
yield return new object[] { "2020-5-7T09:37:00.0000000+00:00", CultureInfo.InvariantCulture, TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2020, 5, 7, 9, 37, 0, DateTimeKind.Utc), TimeZoneInfo.Local) };
1730+
17141731
if (PlatformDetection.IsNotInvariantGlobalization)
17151732
{
17161733
DateTime today = DateTime.Today;

0 commit comments

Comments
 (0)