Created
July 17, 2014 10:13
-
-
Save yukitos/b1d0c01c449455926f6e to your computer and use it in GitHub Desktop.
Easy Datetime.Min/Max implementation.
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
internal static class DateTimeUtil | |
{ | |
public static DateTime Min(params DateTime[] values) | |
{ | |
if (values == null) | |
throw new ArgumentNullException("values"); | |
var comparer = new DateTimeComparer(); | |
Array.Sort<DateTime>(values, comparer); | |
return values[0]; | |
} | |
public static DateTime Max(params DateTime[] values) | |
{ | |
if (values == null) | |
throw new ArgumentNullException("values"); | |
var comparer = new DateTimeComparer(); | |
Array.Sort<DateTime>(values, comparer); | |
return values[values.Length - 1]; | |
} | |
} | |
internal class DateTimeComparer : IComparer<DateTime> | |
{ | |
int IComparer<DateTime>.Compare(DateTime x, DateTime y) | |
{ | |
var v1 = x.ToUniversalTime(); | |
var v2 = y.ToUniversalTime(); | |
return v1.CompareTo(v2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment