This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MyExtensions | |
{ | |
public static System.TimeSpan Months(this Int32 x) | |
{ | |
return System.DateTime.Today.AddMonths(x) - System.DateTime.Today; | |
} | |
public static System.TimeSpan Years(this Int32 x) | |
{ | |
return System.DateTime.Today.AddYears(x) - System.DateTime.Today; | |
} | |
public static System.TimeSpan Years(this Double x) | |
{ | |
return System.DateTime.Today.AddDays(x) - System.DateTime.Today; | |
} | |
public static System.DateTime Ago(this System.TimeSpan x) | |
{ | |
return System.DateTime.Now.Add(x.Negate()); | |
} | |
public static System.DateTime FromNow(this System.TimeSpan x) | |
{ | |
return System.DateTime.Now.Add(x); | |
} | |
public static System.DateTime FromToday(this System.TimeSpan x) | |
{ | |
return System.DateTime.Today.Add(x); | |
} | |
} | |
void Main() | |
{ | |
Console.WriteLine(3.Months().Ago()); | |
Console.WriteLine(3.Years().FromToday()); | |
} | |
So, what do you think ?
BTW, I tested this in LinqPad, may need something extra to become a full program