Permalink
Browse files

Environment.Ticks doesn't have enough resolution for the TimeUUID's c…

…lockSequence issue #66
  • Loading branch information...
1 parent 794d97f commit e8ccbe949bcff3e153f0be585f960eadf0e77595 @nberardi nberardi committed Sep 21, 2012
Showing with 16 additions and 9 deletions.
  1. +8 −1 src/GuidGenerator.cs
  2. +8 −8 src/System/Numerics/BigDecimal.cs
@@ -49,7 +49,14 @@ public static GuidVersion GetVersion(this Guid guid)
private static byte[] ClockSequence
{
- get { return BitConverter.GetBytes(Convert.ToInt16(Environment.TickCount % Int16.MaxValue)); }
+ get
+ {
+ var ts = Stopwatch.GetTimestamp();
+ return new byte[] {
+ (byte)(ts),
+ (byte)(ts >> 0x8)
+ };
+ }
}
public static DateTimeOffset GetDateTimeOffset(Guid guid)
@@ -103,20 +103,20 @@ private static byte[] FromDecimal(decimal d)
int hi = bits[2];
int flags = bits[3];
- bytes[0] = (byte)lo;
- bytes[1] = (byte)(lo >> 8);
+ bytes[0] = (byte)(lo);
+ bytes[1] = (byte)(lo >> 0x8);
bytes[2] = (byte)(lo >> 0x10);
bytes[3] = (byte)(lo >> 0x18);
- bytes[4] = (byte)mid;
- bytes[5] = (byte)(mid >> 8);
+ bytes[4] = (byte)(mid);
+ bytes[5] = (byte)(mid >> 0x8);
bytes[6] = (byte)(mid >> 0x10);
bytes[7] = (byte)(mid >> 0x18);
- bytes[8] = (byte)hi;
- bytes[9] = (byte)(hi >> 8);
+ bytes[8] = (byte)(hi);
+ bytes[9] = (byte)(hi >> 0x8);
bytes[10] = (byte)(hi >> 0x10);
bytes[11] = (byte)(hi >> 0x18);
- bytes[12] = (byte)flags;
- bytes[13] = (byte)(flags >> 8);
+ bytes[12] = (byte)(flags);
+ bytes[13] = (byte)(flags >> 0x8);
bytes[14] = (byte)(flags >> 0x10);
bytes[15] = (byte)(flags >> 0x18);

0 comments on commit e8ccbe9

Please sign in to comment.