I don’t think I like the name, but I couldn’t come up with something better.
public static bool IsWithin(this DateTime datetime, TimeSpan distance) {
var now = DateTime.Now;
return (now – datetime).Duration() < distance;
}
public static bool IsWithin(this DateTime datetime, TimeSpan distance, DateTime now) {
return (now – datetime).Duration() < distance;
}
Coupled with extension methods from yesterday you can write code like this:
if ( postDate.IsWithin(24.Hours()) ) { … }
nice and readable.