Class: Cassandra::TimeUuid
- Includes:
- Comparable
- Defined in:
- lib/cassandra/time_uuid.rb
Overview
A variant of UUID which can extract its time component.
You can use Uuid::Generator to generate TimeUuids
Instance Method Summary collapse
-
#<=>(other) ⇒ nil, Integer
Compares this timeuuid with another timeuuid.
-
#to_date ⇒ Date
Returns the date component from this UUID as Date.
-
#to_time ⇒ Time
Returns the time component from this UUID as a Time.
Methods inherited from Uuid
#hash, #initialize, #to_s, #value
Constructor Details
This class inherits a constructor from Cassandra::Uuid
Instance Method Details
#<=>(other) ⇒ nil, Integer
Compares this timeuuid with another timeuuid
54 55 56 57 58 59 |
# File 'lib/cassandra/time_uuid.rb', line 54 def <=>(other) return nil unless other.kind_of?(Cassandra::Uuid) c = self.value <=> other.value return c if c == 0 || !other.is_a?(Cassandra::TimeUuid) self.time_bits <=> other.time_bits end |
#to_date ⇒ Date
Returns the date component from this UUID as Date.
This just sugar around #to_time
42 43 44 |
# File 'lib/cassandra/time_uuid.rb', line 42 def to_date to_time.to_date end |
#to_time ⇒ Time
Returns the time component from this UUID as a Time.
29 30 31 32 33 34 35 |
# File 'lib/cassandra/time_uuid.rb', line 29 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 |