Fix dates to return as UTC.

Signed-off-by: Mike Dirolf <mike@dirolf.com>
This commit is contained in:
David James 2009-07-17 04:02:57 +08:00 committed by Mike Dirolf
parent dbd656580d
commit 91b1b0ad8f
3 changed files with 9 additions and 2 deletions

View File

@ -245,7 +245,7 @@ class BSON
def deserialize_date_data(buf)
millisecs = buf.get_long()
Time.at(millisecs.to_f / 1000.0) # at() takes fractional seconds
Time.at(millisecs.to_f / 1000.0).utc
end
def deserialize_boolean_data(buf)

View File

@ -58,7 +58,7 @@ class XMLToRuby
when 'array'
array_to_ruby(e.elements)
when 'date'
Time.at(e.text.to_f / 1000.0)
Time.at(e.text.to_f / 1000.0).utc
when 'regex'
regex_to_ruby(e.elements)
when 'null'

View File

@ -117,6 +117,13 @@ class BSONTest < Test::Unit::TestCase
assert_in_delta doc['date'], doc2['date'], 0.001
end
def test_date_returns_as_utc
doc = {'date' => Time.now}
@b.serialize(doc)
doc2 = @b.deserialize
assert_equal "UTC", doc2['date'].zone
end
def test_dbref
oid = ObjectID.new
doc = {}