Class GuidExtensions
- Namespace
- DynaSharp
- Assembly
- DynaSharp.dll
The bounds of the version-7 Guid values of one millisecond, for a range of time over a key of CreateVersion7(DateTimeOffset) ids.
public static class GuidExtensions
- Inheritance
-
GuidExtensions
- Inherited Members
Remarks
A version-7 Guid starts with the milliseconds since the Unix epoch, in 48 bits, big-endian, and ends with random bits, so the lowercase text that DynaSharp stores for a
Guid, in a key and in an attribute, sorts by time: 019a4a2e-5c00-7… of one millisecond before 019a4a2e-5c01-7… of the next. Within one millisecond the random bits
decide. FirstVersion7(DateTimeOffset) and LastVersion7(DateTimeOffset) are the lowest and highest such value of a millisecond, so every id that
CreateVersion7(DateTimeOffset) makes in it lies between them, both included.
They go where the sort key takes a Guid. With [SortKey("{Id}")], Keys.Sk.Between(Guid.FirstVersion7(from), Guid.LastVersion7(to)) reads the ids from the millisecond of
from to that of to, both whole, Keys.Sk.Ge(Guid.FirstVersion7(from)) reads from from on, and Keys.Sk.Lt(Guid.FirstVersion7(to)) stops before to. A
NewGuid(), version 4, is random from its first bit and has no such order.
Methods
FirstVersion7(DateTimeOffset)
Returns the lowest version-7 Guid of the millisecond that holds an instant: its time, and every random bit 0.
public static Guid FirstVersion7(DateTimeOffset at)
Parameters
atDateTimeOffsetThe instant. Its offset does not matter, and what it holds below a millisecond is dropped, as CreateVersion7(DateTimeOffset) drops it.
Returns
- Guid
The value, such as
019a4a2e-5c00-7000-8000-000000000000, which sorts below every other version-7 value of that millisecond and above every value of the one before.
Exceptions
- ArgumentOutOfRangeException
atis before the Unix epoch, which a version-7 value cannot hold.
LastVersion7(DateTimeOffset)
Returns the highest version-7 Guid of the millisecond that holds an instant: its time, and every random bit 1.
public static Guid LastVersion7(DateTimeOffset at)
Parameters
atDateTimeOffsetThe instant. Its offset does not matter, and what it holds below a millisecond is dropped, as CreateVersion7(DateTimeOffset) drops it.
Returns
- Guid
The value, such as
019a4a2e-5c00-7fff-bfff-ffffffffffff, which sorts above every other version-7 value of that millisecond and below every value of the next.
Exceptions
- ArgumentOutOfRangeException
atis before the Unix epoch, which a version-7 value cannot hold.