Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Added some documentation and some Usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelley Reynolds committed Aug 18, 2011
1 parent 9d73f4c commit 516f01c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.rdoc
Expand Up @@ -22,7 +22,13 @@ Install the gem:

== Usage

TBD...
# Creating and getting a timestamp from the UUID
uuid = SimpleUUID::UUID.new => <UUID#2278170300 .... >
uuid.to_time => Thu Aug 18 19:15:16 -0400 2011

# Given raw bytes from a source such as cassandra (using bytes from an existing UUID as an example)
bytes = SimpleUUID::UUID.new.bytes
SimpleUUID::UUID.to_time(bytes) => Thu Aug 18 19:15:16 -0400 2011

== Reporting problems

Expand Down
3 changes: 3 additions & 0 deletions lib/simple_uuid.rb
Expand Up @@ -127,14 +127,17 @@ def eql?(other)
other.respond_to?(:bytes) && bytes == other.bytes
end

# Given raw bytes, return a time object
def self.to_time(bytes)
Time.at(total_usecs(bytes) / 1000000.0)
end

# Return a time object
def to_time
self.class.to_time(@bytes)
end

# Given raw bytes, return the total_usecs
def self.total_usecs(bytes)
elements = bytes.unpack("NnnQ")
(elements[0] + (elements[1] << 32) + ((elements[2] & 0x0FFF) << 48) - GREGORIAN_EPOCH_OFFSET) / 10
Expand Down

0 comments on commit 516f01c

Please sign in to comment.