Last active
August 29, 2015 14:20
-
-
Save bjartwolf/ebe5d42d1b55de7089b3 to your computer and use it in GitHub Desktop.
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
/// <summary> | |
/// Encodes for storing in Azure Table store to get correct ordering | |
/// </summary> | |
/// <param name="date">Use UTC</param> | |
public static string InverseDateTime(this DateTime date) | |
{ | |
var newDate = DateTime.MaxValue.Ticks - date.Ticks; | |
return newDate.ToString(CultureInfo.InvariantCulture); | |
} | |
/// <summary> | |
/// Parses the string representation inverse dates produced by InverseDateTime | |
/// </summary> | |
/// <param name="inversedDate">Use UTC</param> | |
public static DateTime DecodeInverseDateTime(string inversedDate) | |
{ | |
var ticks = long.Parse(inversedDate); | |
var inverseTicks = DateTime.MaxValue.Ticks - ticks; | |
return new DateTime(inverseTicks); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment