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
Constructor Details
This class inherits a constructor from Cassandra::Uuid
Instance Method Details
#<=>(other) ⇒ nil, Integer
Compares this timeuuid with another timeuuid
59 60 61 62 63 64 |
# File 'lib/cassandra/time_uuid.rb', line 59 def <=>(other) return nil unless other.is_a?(Cassandra::Uuid) c = value <=> other.value return c if c == 0 || !other.is_a?(Cassandra::TimeUuid) time_bits <=> other.time_bits end |
#to_date ⇒ Date
Returns the date component from this UUID as Date.
This just sugar around #to_time
47 48 49 |
# File 'lib/cassandra/time_uuid.rb', line 47 def to_date to_time.to_date end |
#to_time ⇒ Time
Returns the time component from this UUID as a Time.
34 35 36 37 38 39 40 |
# File 'lib/cassandra/time_uuid.rb', line 34 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 |