class Cassandra::TimeUuid
A variant of UUID which can extract its time component.
You can use {Cassandra::Uuid::Generator} to generate {Cassandra::TimeUuid}s
Constants
- GREGORIAN_OFFSET
@private
- LOWER_HALF_MASK
@private
Public Instance Methods
<=>(other)
click to toggle source
Compares this timeuuid with another timeuuid
@param other [Cassandra::TimeUuid] another timeuuid to compare @see Comparable
@return [nil] when other is not a {Cassandra::Uuid} @return [Integer] `-1` when less than `other`, `0` when equal to `other`
and `1` when greater than `other`
# File lib/cassandra/time_uuid.rb 59 def <=>(other) 60 return nil unless other.is_a?(Cassandra::Uuid) 61 c = value <=> other.value 62 return c if c == 0 || !other.is_a?(Cassandra::TimeUuid) 63 time_bits <=> other.time_bits 64 end
to_date()
click to toggle source
Returns the date component from this UUID as Date.
This just sugar around {#to_time}
@return [Date]
# File lib/cassandra/time_uuid.rb 47 def to_date 48 to_time.to_date 49 end
to_time()
click to toggle source
Returns the time component from this UUID as a Time
.
@return [Time]
# File lib/cassandra/time_uuid.rb 34 def to_time 35 t = time_bits - GREGORIAN_OFFSET 36 seconds = t / 10_000_000 37 microseconds = (t - seconds * 10_000_000) / 10.0 38 39 ::Time.at(seconds, microseconds).utc 40 end
Protected Instance Methods
time_bits()
click to toggle source
@private
# File lib/cassandra/time_uuid.rb 69 def time_bits 70 n = (value >> 64) 71 t = 0 72 t |= (n & 0x0000000000000fff) << 48 73 t |= (n & 0x00000000ffff0000) << 16 74 t |= (n & 0xffffffff00000000) >> 32 75 t 76 end