Skip to content

Instantly share code, notes, and snippets.

@yukitos
Created July 17, 2014 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukitos/b1d0c01c449455926f6e to your computer and use it in GitHub Desktop.
Save yukitos/b1d0c01c449455926f6e to your computer and use it in GitHub Desktop.
Easy Datetime.Min/Max implementation.
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