I was looking for existing method(s) in .Net C# that add up Gregorian duration ISO 8681 to start date to come up with end date.
For Example :
Start Date : 2007-03-01
Duration : P1Y2M10D
End Date : (Start Date + Duration) = 2008-05-11 // Pseudocode
: P1Y2M10D + 2007-03-01 = 2008-05-11 // Actual Representation
Is their any existing method in .Net that already does it automaticaly before I manually do it on my own? "Time handling is tricky so I preferred to use existing method if their any."
Note : I researched for this functionality but can not find it in internet even in visual studio intellesence. I omitted other designator like Time (T) to reduced precision but it could be completed for example of complete duration is P1Y2M10DT2H30M.
My Noda Time project is able to parse ISO-8601 durations as Period
objects, which can then be used for calendrical arithmetic with LocalDate
or LocalDateTime
values. For example:
var pattern = PeriodPattern.NormalizingIsoPattern;
var text = "P1Y2M10D";
var start = new LocalDate(2007, 3, 1);
var period = pattern.Parse(text).Value;
var end = start + period;
Console.WriteLine("{0:yyyy-MM-dd}", end); // 2008-05-11
I don't believe there's anything in regular .NET which is equivalent.
See more on this question at Stackoverflow