Created
October 1, 2010 21:19
-
-
Save mikeobrien/606878 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
public class GuidCombGenerator : IIdentifierGenerator | |
{ | |
// Methods | |
public object Generate(ISessionImplementor session, object obj) | |
{ | |
return this.GenerateComb(); | |
} | |
private Guid GenerateComb() | |
{ | |
byte[] destinationArray = Guid.NewGuid().ToByteArray(); | |
DateTime time = new DateTime(0x76c, 1, 1); | |
DateTime now = DateTime.Now; | |
TimeSpan span = new TimeSpan(now.Ticks - time.Ticks); | |
TimeSpan timeOfDay = now.TimeOfDay; | |
byte[] bytes = BitConverter.GetBytes(span.Days); | |
byte[] array = BitConverter.GetBytes((long) (timeOfDay.TotalMilliseconds / 3.333333)); | |
Array.Reverse(bytes); | |
Array.Reverse(array); | |
Array.Copy(bytes, bytes.Length - 2, destinationArray, destinationArray.Length - 6, 2); | |
Array.Copy(array, array.Length - 4, destinationArray, destinationArray.Length - 4, 4); | |
return new Guid(destinationArray); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment