-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Support for ISO8601 durations in TimeSpan #28862
Comments
Implementation note: we'd have to adopt a non-quite-conforming parser/formatter (similar to Java's |
|
This would be a great first step for https://github.com/dotnet/corefx/issues/38641. |
Is there any timeline on this suggestion, or is it currently only a thing on the backlog? |
Related to #29932. In the context of System.Text.Json we have decided that ISO8601 durations (which represent duration relative to a point in time) are somewhat incompatible with |
Also interested. I understand that it conflicts with TimeSpan but there are tons of use cases to express duratoins in something else than days (and hours/minutes). Especially since DateTime itself has suitable AddMonths/AddYears/... which are adhering the difference between "P1M" and "P30D" (checked at least for months). I have two cases, one at home and one at work in completely different fields. Would not be there a case for a Iso8601TimeSpan? .NET 8 maybe? 😉 I know it is painful since TimeSpan is so ... fundamental ... but so ISO8601 compliance ;) FYI: @terrajobst |
I would recommend filing a separate API proposal for a potential |
Rationale
As far as I know, there is currently no support for ISO8601 durations for
TimeSpan.Parse
andTimeSpan.ToString
.Per wikipedia's definition , it would allow to write durations like
P10M1D
for a duration of ten month and one day,P1DT2H10M
for 1 day, 2 hours and 10 minutes, orPT0,5M
for 30 seconds.Proposition
TimeSpan.Parse()
accept arguments like the values quoted aboveToString()
format specifier to output values likeP1DT2H
or, if it is not possible for compatibility reasons, add a new.ToISOString()
method.Use cases
XmlConvert.ToString()
to convert this, as suggested hereThe text was updated successfully, but these errors were encountered: