Closed epeshk closed 2 months ago
Hi @epeshk, thanks for sending this, looks like a fantastic improvement :+1:
DateTime(Offset)
format strings don't have any natural maximum length in .NET, so the following kind of thing is valid:
Console.WriteLine("{0:----------------------------------------------}", DateTimeOffset.Now);
I think it's fine to apply a limitation like "format strings can't result in more than 36 chars" but perhaps this could be documented using a constant and a unit test, so that we can be sure if a format string ends up producing output longer than what we'd expect, the results are reasonable?
Definitely in favor of this change otherwise 👍
Reading the code again, I see that we should fall through and still create correct output in the "too long" case - think it just needs a test :-)
Similar to https://github.com/serilog/serilog/pull/2094
Removed allocations from
DateTimeOffset.ToString
by usingISpanFormattable.TryFormat
APIBefore
After