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

Mongoid ignores Time.zone also with use_utc: true (2.0.1 and master)

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.1.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Hi,

      I have two classes one with activerecord and another with mongoid

      class Event  < ActiveRecord::Base #has a field date_time of type datetime
      end
      
      class Event2
        include Mongoid::Document
        field :date_time, :type => DateTime
      end
      

      if I set use_utc:true

      Loading development environment (Rails 3.0.5)
      irb(main):001:0> Time.zone = ActiveSupport::TimeZone["Europe/Berlin"]
      => (GMT+01:00) Europe/Berlin
      irb(main):002:0> a = Event.new
      => #<Event id: nil, date_time: nil, created_at: nil, updated_at: nil>
      irb(main):003:0> a.date_time = Time.zone.now
      => Sun, 24 Apr 2011 18:11:51 CEST +02:00
      irb(main):004:0> a.date_time
      => Sun, 24 Apr 2011 18:11:51 CEST +02:00
      irb(main):005:0> b = Event2.new
      => #<Event2 _id: 4db44bde54f71f0dd8000001, _type: nil, date_time: nil>
      irb(main):006:0> b.date_time = Time.zone.now
      => Sun, 24 Apr 2011 18:12:22 CEST +02:00
      irb(main):007:0> b.date_time
      => Sun, 24 Apr 2011 16:12:22 +0000
      

      if I set use_utc:false (and server Time.zone = "America/Chicago"):

      Loading development environment (Rails 3.0.5)
      irb(main):001:0> Time.zone = ActiveSupport::TimeZone["Europe/Berlin"]
      => (GMT+01:00) Europe/Berlin
      irb(main):002:0> a = Event.new
      => #<Event id: nil, date_time: nil, created_at: nil, updated_at: nil>
      irb(main):003:0> a.date_time = Time.zone.now
      => Sun, 24 Apr 2011 18:18:40 CEST +02:00
      irb(main):004:0> a.date_time
      => Sun, 24 Apr 2011 18:18:40 CEST +02:00
      irb(main):005:0> b = Event2.new
      => #<Event2 _id: 4db44d6a54f71f1ac4000001, _type: nil, date_time: nil>
      irb(main):006:0> b.date_time = Time.zone.now
      => Sun, 24 Apr 2011 18:18:59 CEST +02:00
      irb(main):007:0> b.date_time
      => Sun, 24 Apr 2011 11:18:59 -0500
      

      I think that the correct behaviour would be the ActiverRecord: stores as utc but shows in user Time.zone
      This cause problems using ActiveView::Helpers like datetime_select.

      This happends in 2.0.1 and master

      Regards

            Assignee:
            Unassigned Unassigned
            Reporter:
            TLmaK0 TLmaK0 [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: