Closed sgringwe closed 7 years ago
A snippet of your model validation code code would be very useful here. But it looks like the date given in the validation is a Date
object while @appointment.end_date
is an ActiveSupport::TimeWithZone
object.
Try this -
DATE_GIVEN_IN_THE_VALIDATION.in_time_zone.utc
@appointment.end_date.utc
I think you will find that the validation is right :)
@akshaysmurthy my validations are
validates :start_date, presence: true, date: {}
validates :end_date, presence: true, date: { on_or_after: :start_date }
both are a datetime in the db
# start_date :datetime
# end_date :datetime
but it's possible rails is interpreting them differently from the server?
@sgringwe
If you look at https://github.com/codegram/date_validator/blob/master/lib/active_model/validations/date_validator.rb#L15, you'll see that on_or_after
is not a valid check. You should use after_or_equal_to
.
Our tests run in random time zones. In some of the time zones, the date validator does not seem to work:
The code:
The output: