Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5171,7 +5171,9 @@ private static bool TryParseFormatO(ReadOnlySpan<char> source, scoped ref DateTi
second = (int)(s1 * 10 + s2);
}

double fraction;
// The seven fractional digits are sub-second ticks (1 tick = 100 ns = 10^-7 s),
// matching TimeSpan.TicksPerSecond, so we can use them directly without floating-point math.
int fractionTicks;
{
uint f1 = (uint)(source[20] - '0');
uint f2 = (uint)(source[21] - '0');
Expand All @@ -5187,12 +5189,12 @@ private static bool TryParseFormatO(ReadOnlySpan<char> source, scoped ref DateTi
return false;
}

fraction = (f1 * 1000000 + f2 * 100000 + f3 * 10000 + f4 * 1000 + f5 * 100 + f6 * 10 + f7) / 10000000.0;
fractionTicks = (int)(f1 * 1000000 + f2 * 100000 + f3 * 10000 + f4 * 1000 + f5 * 100 + f6 * 10 + f7);
}

// Per ISO 8601, 24:00:00 represents the end of a calendar day
// (the same instant as the next day's 00:00:00), but only when minute, second, and fraction are all zero
if (hour == 24 && (minute != 0 || second != 0 || fraction != 0))
if (hour == 24 && (minute != 0 || second != 0 || fractionTicks != 0))
{
result.SetBadDateTimeFailure();
return false;
Expand All @@ -5204,7 +5206,7 @@ private static bool TryParseFormatO(ReadOnlySpan<char> source, scoped ref DateTi
return false;
}

if (!dateTime.TryAddTicks((long)Math.Round(fraction * TimeSpan.TicksPerSecond), out result.parsedDate))
if (!dateTime.TryAddTicks(fractionTicks, out result.parsedDate))
{
result.SetBadDateTimeFailure();
return false;
Expand Down
Loading