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

Different DateTime are handled differently

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None

      It seems that some DateTime are not handled properly when passed to Mongoid documents.

      muichkine@ubuntu:~/src/white$ rails c
      Loading development environment (Rails 4.0.1)
      2.0.0p353 :001 > class A
      2.0.0p353 :002?> include Mongoid::Document
      2.0.0p353 :003?> field :doc, :type => DateTime
      2.0.0p353 :004?> end
      => #<Mongoid::Fields::Standard:0x0000000a1c30b8 @name="doc", @options={:type=>DateTime, :klass=>A}, @label=nil, @default_val=nil>
      2.0.0p353 :005 > first_date = DateTime.new(1582,1,1)
      => Mon, 01 Jan 1582 00:00:00 +0000
      2.0.0p353 :006 > second_date = DateTime.new(1583,1,1)
      => Sat, 01 Jan 1583 00:00:00 +0000
      2.0.0p353 :007 > first_a = A.new(:doc => first_date)
      => #<A _id: 529f2cfa7562754218000000, doc: 1582-01-11 00:00:00 UTC> #WRONG
      2.0.0p353 :008 > second_a = A.new(:doc => second_date)
      => #<A _id: 529f2d167562754218010000, doc: 1583-01-01 00:00:00 UTC>

      Is there any reason for this behavior or known limitation? Some instrumental tests for my app fail due to this here. I haven't be able to narrow a rule to trigger that behavior. Above is just an example I could come up with. This is even more painful since my test DateTime are randomized.

      Feedback on this is much appreciated.

            Assignee:
            durran Durran Jordan
            Reporter:
            muichkine Olivier Milla
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: