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

Mongoid 3 is UTCifying times that are already in UTC

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • None

      I have use_utc turned on, and I do this in US Eastern time:

      class Post
        include Mongoid::Document
      
        field :name
        field :time, type: DateTime
      end
      
      puts "current local time #{DateTime.now}"
      puts "current UTC time #{DateTime.now.utc}"
      
      Post.create(name: "Now local", time: DateTime.now).save!
      Post.create(name: "Now UTC", time: DateTime.now.utc).save!
      
      Post.all.each{|p| puts "#{p.name}: #{p.time}"}
      

      In 2.4, it does this, as expected:

      current local time 2012-06-10T20:37:24-04:00
      current UTC time 2012-06-11T00:37:24+00:00
      MONGODB (0ms) repro2['system.namespaces'].find({})
      MONGODB (0ms) repro2['$cmd'].find({:create=>"posts"}).limit(-1)
      MONGODB (0ms) repro2['posts'].insert([{"_id"=>BSON::ObjectId('4fd53dc48ace23781f000001'), "name"=>"Now local", "time"=>2012-06-11 00:37:24 UTC}])
      MONGODB (0ms) repro2['posts'].insert([{"_id"=>BSON::ObjectId('4fd53dc48ace23781f000002'), "name"=>"Now UTC", "time"=>2012-06-11 00:37:24 UTC}])
      MONGODB (0ms) repro2['posts'].find({})
      Now local: 2012-06-11T00:37:24+00:00
      Now UTC: 2012-06-11T00:37:24+00:00
      

      But in 3.0.rc, it does this:

      current local time 2012-06-10T20:40:24-04:00
      current UTC time 2012-06-11T00:40:24+00:00
        MOPED: localhost:27017 INSERT       database=repro3 collection=posts documents=[{"_id"=>4fd53e788ace23b67b000001, "name"=>"Now local", "time"=>2012-06-11 00:40:24 UTC}] flags=[] (0.0ms)
        MOPED: localhost:27017 INSERT       database=repro3 collection=posts documents=[{"_id"=>4fd53e788ace23b67b000002, "name"=>"Now UTC", "time"=>2012-06-11 04:40:24 UTC}] flags=[] (0.0ms)
        MOPED: localhost:27017 QUERY        database=repro3 collection=posts selector={} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.0ms)
      Now local: 2012-06-10T20:40:24-04:00
      Now UTC: 2012-06-11T00:40:24-04:00
      

      So basically, it's ignoring that the time is already in UTC and converting it anyway, making it off by 4 hours. (Side note: they're also expressed as local times, which is a bit weird, but I think that in my actual app active_support_time_zones will fix that).

            Assignee:
            Unassigned Unassigned
            Reporter:
            icambron Isaac Cambron
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: