Added generation_time method on ObjectID
This commit is contained in:
parent
0161ea3962
commit
4550389480
@ -124,6 +124,12 @@ module Mongo
|
|||||||
legacy
|
legacy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the utc time at which this ObjectID was generated. This may
|
||||||
|
# be used in lieu of a created_at timestamp.
|
||||||
|
def generation_time
|
||||||
|
Time.at(@data.pack("C4").unpack("N")[0])
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -121,4 +121,10 @@ class ObjectIDTest < Test::Unit::TestCase
|
|||||||
assert_equal s, ObjectID.legacy_string_convert(l)
|
assert_equal s, ObjectID.legacy_string_convert(l)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_generation_time
|
||||||
|
time = Time.now
|
||||||
|
id = ObjectID.new
|
||||||
|
|
||||||
|
assert_in_delta time.to_i, id.generation_time.to_i, 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user