Skip to content

Instantly share code, notes, and snippets.

@christo8989
Created June 28, 2017 21:06
Show Gist options
  • Save christo8989/b5c257fdfaf9cb22eb6703131b62d8bc to your computer and use it in GitHub Desktop.
Save christo8989/b5c257fdfaf9cb22eb6703131b62d8bc to your computer and use it in GitHub Desktop.
Extending DateTime for common queries. Follows the same method names as MomentJs.
//http://momentjs.com/docs/#/query
public static class DateTimeExtensions
{
public static bool IsSame(this DateTime source, DateTime value)
{
return source.CompareTo(value) == 0;
}
public static bool IsBefore(this DateTime source, DateTime value)
{
return source.CompareTo(value) < 0;
}
public static bool IsSameOrBefore(this DateTime source, DateTime value)
{
return source.CompareTo(value) <= 0;
}
public static bool IsAfter(this DateTime source, DateTime value)
{
return source.CompareTo(value) > 0;
}
public static bool IsSameOrAfter(this DateTime source, DateTime value)
{
return source.CompareTo(value) >= 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment