Class: Cql::TimeUuid

Inherits:
Uuid
  • Object
show all
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

#eql?, #hash, #initialize, #to_s, #value

Constructor Details

This class inherits a constructor from Cql::Uuid

Instance Method Details

#to_timeTime

Returns the time component from this UUID as a Time.

Returns:

  • (Time)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cql/time_uuid.rb', line 11

def to_time
  n = (value >> 64)
  t = 0
  t |= (n & 0x0000000000000fff) << 48
  t |= (n & 0x00000000ffff0000) << 16
  t |= (n & 0xffffffff00000000) >> 32
  t -= GREGORIAN_OFFSET
  seconds = t/10_000_000
  microseconds = (t - seconds * 10_000_000)/10.0
  Time.at(seconds, microseconds).utc
end