How to validate time between 20 minutes to 48 hours?
haikalhussein opened this issue · 3 comments
haikalhussein commented
I'm using rails 4 and the gem works. But now i got a situation whereby a user's time is between 20 minutes to 48 hours. Is it possible to validate ?
adzap commented
If I understand you correctly you probably want something like this
validate_datetime :some_attribute, on_or_after: proc {|r| 20.minutes.since(r.other_attribute) },
on_or_before: proc {|r| 48.hours.since(r.other_attribute) }
Which depends on other_attribute
being present of course. Is that what you are looking for?
haikalhussein commented
Sorry my bad. But my data type in psql is interval. Can the gem validates for column type interval, where it can store data like "48:00:00". Because currently the timespan does not require any specific end points.
adzap commented
no doesn't support intervals. I imagine you just validate intervals as a value object. I've not handled intervals in Rails, just directly in sql.