Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5091

Queries on Date fields specs fail when running in UTC+ timezones

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.3.0
    • Affects Version/s: None
    • Component/s: None

      Mongoid specs for Date fields implicitly assumes they are executed in UTC-X time zones. Therefore they pass in, say, on Evergreen, but fails, say, in Europe.

       

       

      ➜  mongoid git:(master) bundle exec rspec spec/integration/criteria/date_field_spec.rb
      
      1) Queries on Date fields using Time behaves like converts to beginning of day in UTC converts to beginning of day in UTC
           Failure/Error: selector['founded'].should == arg.dup.beginning_of_day.utc.beginning_of_day       expected: 2021-05-02 00:00:00.000000000 +0000
                  got: 2021-05-03 00:00:00.000000000 +0000 (using ==)
             Diff:
             @@ -1 +1 @@
             -2021-05-02 00:00:00 UTC
             +2021-05-03 00:00:00 UTC     Shared Example Group: "converts to beginning of day in UTC" called from ./spec/integration/criteria/date_field_spec.rb:24
           # ./spec/integration/criteria/date_field_spec.rb:15:in `block (3 levels) in <top (required)>'
        2) Queries on Date fields using DateTime behaves like converts to beginning of day in UTC converts to beginning of day in UTC
           Failure/Error: selector['founded'].should == arg.dup.beginning_of_day.utc.beginning_of_day       expected: 2021-05-02 00:00:00.000000000 +0000
                  got: 2021-05-03 00:00:00.000000000 +0000 (using ==)
             Diff:
             @@ -1 +1 @@
             -2021-05-02 00:00:00 UTC
             +2021-05-03 00:00:00 UTC     Shared Example Group: "converts to beginning of day in UTC" called from ./spec/integration/criteria/date_field_spec.rb:39
           # ./spec/integration/criteria/date_field_spec.rb:15:in `block (3 levels) in <top (required)>' 3/3 
      
      3 examples, 2 failuresFailed examples:
      rspec './spec/integration/criteria/date_field_spec.rb[1:1:1:1]' # Queries on Date fields using Time behaves like converts to beginning of day in UTC converts to beginning of day in UTC
      rspec './spec/integration/criteria/date_field_spec.rb[1:3:1:1]' # Queries on Date fields using DateTime behaves like converts to beginning of day in UTC converts to beginning of day in UTC
      

       

      Mongoid specs should not depend on time zone they are executed in.

       

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: