3

I have stored data that has a UUID v1 as key and I now want to know when the UUID was generated. How do I do that the nice way?

mhk
  • 161
  • 6
  • Here is how it is done in python http://stackoverflow.com/questions/3795554/extract-the-time-from-a-uuid-v1-in-python maybe use it as a template. – ThatGuyInIT Jul 14 '11 at 16:21
  • I found [this little recipe](http://code.activestate.com/recipes/576420-get-a-posix-timestamp-from-a-type-1-uuid/) in Python. Since I'm not good at Ruby, could someone make this for Ruby please? – mhk Jul 14 '11 at 18:31

1 Answers1

2

This works with irb:

require 'simple_uuid'
uuid = SimpleUUID::UUID.new
uuid.to_guid # actually this is what I have stored in my database
Time.at(SimpleUUID::UUID.new(uuid.to_guid).seconds) # returns the time and date of the UUID

Thanks to my friend KillerFox, he showed me the simple solution.

mhk
  • 161
  • 6