Class: Cql::TimeUuid

Inherits:
Uuid
  • Object
show all
Includes:
Comparable
Defined in:
lib/cql/time_uuid.rb

Overview

A variant of UUID which can extract its time component.

Defined Under Namespace

Classes: Generator

Instance Method Summary collapse

Methods inherited from Uuid

#hash, #initialize, #to_s, #value

Constructor Details

This class inherits a constructor from Cql::Uuid

Instance Method Details

#<=>(other) ⇒ Object



20
21
22
23
24
# 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_timeTime

Returns the time component from this UUID as a Time.

Returns:

  • (Time)


13
14
15
16
17
18
# 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