Class: Cql::TimeUuid
Overview
A variant of UUID which can extract its time component.
Defined Under Namespace
Classes: Generator
Instance Method Summary collapse
-
#to_time ⇒ Time
Returns the time component from this UUID as a Time.
Methods inherited from Uuid
#eql?, #hash, #initialize, #to_s, #value
Constructor Details
This class inherits a constructor from Cql::Uuid
Instance Method Details
#to_time ⇒ Time
Returns the time component from this UUID as a 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 |