Skip to content

thomaslevesque/Iso8601DurationHelper

Repository files navigation

Iso8601DurationHelper

NuGet versionAppVeyor buildAppVeyor tests

A small library to handle ISO8601 durations (e.g. P1Y for 1 year, PT2H30M for 2 hours and 30 minutes) in C#.

Some libraries attempt to parse these durations to TimeSpan, but it doesn't really make sense, because TimeSpan doesn't have a concept of month, so they just translate P1M to 30 days. This is wrong because all months don't have the same number of days; January 1 + 1 month should be February 1, not January 31.

This library introduces a Duration struct with operators to add a duration to or subtract a duration from a date, with the proper semantics. For instance:

varstartDate=newDateTime(2018,1,1);varduration=Duration.Parse("P2M");varendDate=startDate+duration;// 2018/03/01

About

Small library to handle ISO8601 durations in C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •