diff --git a/README.rdoc b/README.rdoc index c50ef5b..79885ea 100644 --- a/README.rdoc +++ b/README.rdoc @@ -290,6 +290,9 @@ John Nunemaker, http://railstips.org * Collection#create_index takes symbols as well as strings * Fix for Collection#save +David James, djames@sunlightfoundation.com +* Fix dates to return as UTC + = License Copyright 2008-2009 10gen Inc. diff --git a/ext/cbson/cbson.c b/ext/cbson/cbson.c index a925124..4a3d1e6 100644 --- a/ext/cbson/cbson.c +++ b/ext/cbson/cbson.c @@ -541,6 +541,7 @@ static VALUE get_value(const char* buffer, int* position, int type) { VALUE microseconds = INT2NUM((millis % 1000) * 1000); value = rb_funcall(Time, rb_intern("at"), 2, seconds, microseconds); + value = rb_funcall(value, rb_intern("utc"), 0) *position += 8; break; } diff --git a/lib/mongo/util/bson.rb b/lib/mongo/util/bson.rb index 72deac6..6a96206 100644 --- a/lib/mongo/util/bson.rb +++ b/lib/mongo/util/bson.rb @@ -245,7 +245,7 @@ class BSON def deserialize_date_data(buf) millisecs = buf.get_long() - Time.at(millisecs.to_f / 1000.0).utc + Time.at(millisecs.to_f / 1000.0).utc # at() takes fractional seconds end def deserialize_boolean_data(buf) diff --git a/lib/mongo/util/xml_to_ruby.rb b/lib/mongo/util/xml_to_ruby.rb index 81a854f..fc7b003 100644 --- a/lib/mongo/util/xml_to_ruby.rb +++ b/lib/mongo/util/xml_to_ruby.rb @@ -58,7 +58,7 @@ class XMLToRuby when 'array' array_to_ruby(e.elements) when 'date' - Time.at(e.text.to_f / 1000.0).utc + Time.at(e.text.to_f / 1000.0) when 'regex' regex_to_ruby(e.elements) when 'null' diff --git a/tests/test_bson.rb b/tests/test_bson.rb index abd05df..e63fc5b 100644 --- a/tests/test_bson.rb +++ b/tests/test_bson.rb @@ -121,7 +121,7 @@ class BSONTest < Test::Unit::TestCase doc = {'date' => Time.now} @b.serialize(doc) doc2 = @b.deserialize - assert_equal "UTC", doc2['date'].zone + assert doc2['date'].utc? end def test_dbref