[SERVER-3441] Timezones with "+hh:mm" or "-hh:mm" work, but those with "Z" don't Created: 18/Jul/11  Updated: 29/Aug/11  Resolved: 18/Jul/11

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.8.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Seamus Abshere Assignee: Unassigned
Resolution: Done Votes: 0
Labels: standards, timezone
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

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" :

{ "started_at" : [ [ "2011-07-18T08:35:21-05:00", "2011-07-18T12:35:21-05:00" ] ] }

}

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" :

{ "started_at" : [ [ "2011-07-18T13:35:21Z", "2011-07-18T17:35:21Z" ] ] }

}

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":"2011-07-18T14:15:30-05:00"}

{ :started_at => Time.now.utc }.to_json #=>

{"started_at":"2011-07-18T19:15:37Z"}

 Comments   
Comment by Seamus Abshere [ 18/Jul/11 ]

Thanks for clarifying this.

It appears that the dates have been stored as Strings on the server itself, which is the source of this problem.

Comment by Scott Hernandez (Inactive) [ 18/Jul/11 ]

Strings are not Dates, and they are not compatible when used in queries.

>new ISODate("2011-07-18T13:35:21Z")
ISODate("2011-07-18T13:35:21Z")
> new ISODate("2011-07-18T08:35:21-05:00")
ISODate("2011-07-18T13:35:21Z")
>new ISODate("2011-07-18T08:35:21-05:00") == "2011-07-18T13:35:21Z"

In ruby that is just pretty printing and not what gets sent to the server.

Generated at Thu Feb 08 03:03:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.