codegram / date_validator

A simple, ORM agnostic, Ruby >=2.2 compatible date validator for Rails, based on ActiveModel.
http://thoughts.codegram.com/date-validation-with-rails-3
MIT License
495 stars 82 forks source link

don't use .to_i to avoid different usec being considered equal #94

Open pesta opened 1 year ago

pesta commented 1 year ago

✍️ Description

(required) Please include any relevant details about this Pull Request, with a focus on:

ApplicationRecord.connection.execute("CREATE TABLE models (id UUID, my_date TIMESTAMP)")

class Model < ApplicationRecord
  validates :my_date, date: { equal_to: ->(model) { model.my_date.end_of_day } }
end

model = Model.new
model.my_date = Time.current.end_of_day.change(usec: 0)
model.valid? # true
model.my_date == model.my_date.end_of_day # false

Based on the test suite, it looks fine.