A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/thomaslevesque/Iso8601DurationHelper below:

thomaslevesque/Iso8601DurationHelper: Small library to handle ISO8601 durations in C#

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:

var startDate = new DateTime(2018, 1, 1);
var duration = Duration.Parse("P2M");
var endDate = startDate + duration; // 2018/03/01

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4