class Cql::TimeUuid

A variant of UUID which can extract its time component.

Constants

GREGORIAN_OFFSET
LOWER_HALF_MASK

Public Instance Methods

<=>(other) click to toggle source
# File lib/cql/time_uuid.rb, line 20
def <=>(other)
  c = self.value <=> other.value
  return c if c == 0
  self.time_bits <=> other.time_bits
end
to_time() click to toggle source

Returns the time component from this UUID as a Time.

@return [Time]

# File lib/cql/time_uuid.rb, line 13
def to_time
  t = time_bits - GREGORIAN_OFFSET
  seconds = t/10_000_000
  microseconds = (t - seconds * 10_000_000)/10.0
  Time.at(seconds, microseconds).utc
end

Protected Instance Methods

time_bits() click to toggle source
# File lib/cql/time_uuid.rb, line 28
def time_bits
  n = (value >> 64)
  t = 0
  t |= (n & 0x0000000000000fff) << 48
  t |= (n & 0x00000000ffff0000) << 16
  t |= (n & 0xffffffff00000000) >> 32
  t
end