Skip to content

Commit

Permalink
Merge pull request #1 from scalex/fix/mz-take-from-beginning-of-date
Browse files Browse the repository at this point in the history
Add take values from beginning of day
  • Loading branch information
crmaxx committed Apr 14, 2015
2 parents b19bd4d + 19e7cf2 commit bd38875
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/active_model/validations/date_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DateValidator < ActiveModel::EachValidator
# Call `#initialize` on the superclass, adding a default
# `allow_nil: false` option.
def initialize(options)
super(options.reverse_merge(allow_nil: false))
super(options.reverse_merge(allow_nil: false, beginning_of_day: true))
end

# Validates the arguments passed to the validator.
Expand Down Expand Up @@ -75,6 +75,11 @@ def validate_each(record, attr_name, value)
original_value = value
original_option_value = option_value

if options[:beginning_of_day]
value = value.beginning_of_day
option_value = option_value.beginning_of_day
end

# To enable to_i conversion, these types must be converted to Datetimes
if defined?(ActiveSupport::TimeWithZone)
option_value = option_value.to_datetime if option_value.is_a?(ActiveSupport::TimeWithZone)
Expand Down

0 comments on commit bd38875

Please sign in to comment.