Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1464

Time offset ignored in aggregation queries when using ActiveSupport::TimeWithZone

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.7.0.rc0
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      ruby-2.3.3 macOS High Sierra
    • 1

      Using the aggregation pipeline with a match query with a `start_date` like this one

      match_date = { '$match': { 'created_at': { '$gte': start_date } }

      It would seem that the offset is ignored when using ActiveSupport::TimeWithZone (astwz) objects that have an offset. 

      Assume the server is in Paris/UTC+2 and

      start_date_astwz = 1.hour.ago #=> Thu, 03 May 2018 09:52:46 CEST +02:00

      Then when using the match date, the time returnes would actually be 

      Thu, 03 May 2018 09:52:46 CEST +00:00 (so 2 hours in the future)

       

      When converting to Time (for instance using `.utc`) it works as expected, so I guess a fix would be to systematically call .utc

      start_date_time = 1.hour.ago.utc #=> "2018-05-03T07:53:33.060Z" # and works fine

       

       

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            CyrilDD Cyril
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: