A variant of UUID which can extract its time component.

You can use Uuid::Generator to generate TimeUuids

Inherits

Includes

  • Comparable

Methods

to_time

Returns the time component from this UUID as a Time.

Returns:
Type Details
Time
Specifications:
TimeUuid#to_time returns a Time
x = TimeUuid.new('00b69180-d0e1-11e2-8b8b-0800200c9a66')
x.to_time.should be > ::Time.utc(2013, 6, 9, 8, 45, 57)
x.to_time.should be < ::Time.utc(2013, 6, 9, 8, 45, 58)

to_date

Returns the date component from this UUID as Date.

This just sugar around #to_time

Returns:
Type Details
Date

<=>

(other)

Compares this timeuuid with another timeuuid

Parameters:
Name Type Details
other TimeUuid another timeuuid to compare
Returns:
Type Details
nil when other is not a Uuid
Integer -1 when less than other, 0 when equal to other and 1 when greater than other
See Also:
  • Comparable
Specifications:
TimeUuid#<=> sorts by the time component
uuids.shuffle.sort.should == uuids
TimeUuid#<=> allows comparison of UUID and TimeUUID
x = generator.now
y = Uuid.new(x.value)
x.should == y
TimeUuid#<=> allows comparison of TimeUUID and nil
x = generator.now
y = nil
lambda { x.should_not == y }.should_not raise_error