What library can I use to calculate dates based on date expressions?
A date expression would be something like:
- “+3D” (plus three days)
- “-1W” (minus one week)
- “-2Y+2D+1M” (minus 2 years, plus one day, plus one month)
Example:
DateTime EstimatedArrivalDate = CalcDate("+3D", DateTime.Now);
Where estimated arrival date would equal the current date plus 3 days.
I have heard about JodaTime and NodaTime but I have not seen anything in them yet that does this. What should I be using to get this functionality in C#?
There is no library (that I’m aware of, including the port of JodaTime to .NET) that will work with expressions like this. As long as the expressions are simply chained (as they are in your example), it should be pretty easy to write a RegEx to parse that expression and do the processing yourself: