Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-3441

Timezones with "+hh:mm" or "-hh:mm" work, but those with "Z" don't

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.2
    • Component/s: Querying
    • ALL

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

            Assignee:
            Unassigned Unassigned
            Reporter:
            seamusabshere Seamus Abshere
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: