Closed Foxtrek64 closed 2 years ago
Closing this issue.
TimeSpan does not support any time periods above days natively.
A better fit is NodaTime.Period
which already includes S.T.J converters under the NodaTime.Serialization.SystemTextJson nuget package.
Edit: see dotnet/runtime#72064
Description ISO8601 describes a duration format, such as
P3Y6M4DT12H30M5S
.The P stands for Period and must start all duration strings.
3Y = 3 years 6M = 6 months 4D = 4 Days T = time separator 12H = 12 hours 30M = 30 minutes 5S = 5 seconds
Why This is Needed
Some APIs use this format for their durations.
Implementation Example
Other Thoughts
TimeStamp.Parse()
does not support this format.XmlConvert
works, but it relies on a reference toSystem.Xml
and there is noTryXXX
methods, so we're stuck with this try/catch pattern. Thoughts welcome.