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

Date decrements on save

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

      I have a document with a date field that decrements by 1 day every time I save. Not really sure whats going on. If I get time I'll see if I can find it, but I thought I should let you know.

      class TourDate
        include Mongoid::Document
        include Mongoid::Timestamps
      
        # Fields --------------------------------------------------------------------
        field :starts_on,         type: Date
        field :number_of_nights,  type: Integer,  :default => 1
        field :available,         type: Boolean,  :default => true
        field :sold_out,          type: Boolean,  :default => false
      
        # Associations --------------------------------------------------------------
        belongs_to :package
      
        # Validations ---------------------------------------------------------------
        validates_presence_of :starts_on, :number_of_nights, :package
      
        # Delegations ---------------------------------------------------------------
        delegate  :name,
                  :to => :package,
                  :prefix => true
      
        # Methods -------------------------------------------------------------------
      
        def availability
          if self.available && self.sold_out
            return "Sold Out"
          elsif self.available && !self.sold_out
            return "Available"
          else
            return "Not Available"
          end
        end
      end
      

      If I load this document into a form and enter 10/10/2012 and click on save, the record saves without error, however the date will be saved as 10/09/2012.

      Using Rails 3.2.6 with Mongoid 3.0.0.rc

      I switched to Mongoid 2.4.11 and it works correctly so it definitely appears to be related to Mongoid 3.x

            Assignee:
            durran Durran Jordan
            Reporter:
            noiseunion noiseunion
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: