According to the W3C (http://www.w3.org/TR/NOTE-datetime) and the IETF (http://tools.ietf.org/html/rfc3339), both ways of representing time zones should be accepted:
- 2011-07-18T08:35:21-05:00 (works!)
- 2011-07-18T13:35:21Z (doesn't work!)
The first way (2011-07-18T08:35:21-05:00) works just fine:
mydbset:PRIMARY> db.MyCollection.find({"started_at":{"$gte":"2011-07-18T08:35:21-05:00","$lt":"2011-07-18T12:35:21-05:00"}}).count()
2789
mydbset:PRIMARY> db.MyCollection.find({"started_at":{"$gte":"2011-07-18T08:35:21-05:00","$lt":"2011-07-18T12:35:21-05:00"}}).explain()
{
"cursor" : "BtreeCursor started_at_1",
"nscanned" : 2791,
"nscannedObjects" : 2791,
"n" : 2791,
"millis" : 2,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" :
}
The second way (2011-07-18T13:35:21Z) fails silently:
mydbset:PRIMARY> db.MyCollection.find({"started_at":{"$gte":"2011-07-18T13:35:21Z","$lt":"2011-07-18T17:35:21Z"}}).count()
0
mydbset:PRIMARY> db.MyCollection.find({"started_at":{"$gte":"2011-07-18T13:35:21Z","$lt":"2011-07-18T17:35:21Z"}}).explain()
{
"cursor" : "BtreeCursor started_at_1",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" :
}
This causes particular problems with the mongo-ruby-driver because Time.now.utc.to_json gives the non-working form:
require 'active_support'
require 'active_support/json'
{ :started_at => Time.now }.to_json #=>
{ :started_at => Time.now.utc }.to_json #=>
{"started_at":"2011-07-18T19:15:37Z"}