Created
June 28, 2017 21:06
-
-
Save christo8989/b5c257fdfaf9cb22eb6703131b62d8bc to your computer and use it in GitHub Desktop.
Extending DateTime for common queries. Follows the same method names as MomentJs.
This file contains hidden or 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
//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