4 ms·
In other news C# is exactly as expressive as Rust and Ruby... void Main() { Console.WriteLine(2.Days().Ago()); Console.WriteLine(4.Days().FromNow());
by sklivvz1971 13y ago
In other news C# is exactly as expressive as Rust and Ruby...
void Main()
{
Console.WriteLine(2.Days().Ago());
Console.WriteLine(4.Days().FromNow());
}
//This can be a library, mmkay?
public static class Extensions
{
public static TimeSpan Days(this int days){ return new TimeSpan(days, 0,0,0); }
public static DateTime FromNow(this TimeSpan howMuch){ return DateTime.Now + howMuch; }
public static DateTime Ago(this TimeSpan howMuch){ return DateTime.Now - howMuch; }
}
Results in:
26/12/2013 22:05:10
01/01/2014 22:05:10
Is there a better example?
- deleted 13y ago[deleted]
- mythz 13y agopublic static class Extensions { public static void Print(this object o) { Console.WriteLine(o); } } 2.Days().Ago().Print(); 4.Days().FromNow().Print();