-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeOnly formats milliseconds wrong with format 'o' #51482
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
.... I think I'm more surprised that |
Tagging subscribers to this area: @tannergooding Issue DetailsIt seems that with format 'o' static void Main(string[] args)
{
Span<char> buffer = new char[22];
var time = new TimeOnly(1, 1, 1, 123);
time.TryFormat(buffer, out int written, "O");
Console.WriteLine('"' + buffer.Slice(0, written).ToString() + '"');
// => "01:01:01.0000001" instead of "01:01:01.1230000"
Console.WriteLine('"' + buffer.ToString() + '"');
// => "01:01:01.0000001230000" TryFormat writes more than charsWritten characters
Console.WriteLine('"' + time.ToString("O") + '"');
// => "01:01:01.1230000" correct
Console.WriteLine(string.Format("\"{0:O}\"", time));
// => "01:01:01.0000000" no milliseconds at all (they are far to the right)
} I think the bug is here runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs Line 1268 in 94c13d0
It should be WriteDigits((uint)fraction, destination.Slice(9, 7));
|
It seems that with format 'o'
TimeOnly.TryFormat()
always fills the whole buffer after the decimal point with '0' and writes 7 decimal places right aligned at the end of the buffer. Regardless it always sets charsWritten = 16.I think the bug is here
runtime/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs
Line 1268 in 94c13d0
It should be
The text was updated successfully, but these errors were encountered: