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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7.0.rc0
    • Component/s: None
    • Labels:
    • Environment:
      ruby-2.3.3 macOS High Sierra
    • Story Points:
      1

      Description

      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

       

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              oleg.pudeyev Oleg Pudeyev
              Reporter:
              CyrilDD Cyril
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: