Topic: simpler date comparisons
I've written a custom validation to stop people setting dates in the past for this particular model (the column is :deadline):
compare_time = self.deadline.to_a[3..5] <=> Time.now.to_a[3..5]
errors.add(:deadline,"can't be set in the past") if compare_time < 0
This makes sure dates are not in the past without bothering with seconds, minutes, etc which don't matter. It does the job but is there a DRYer way of doing it?
Last edited by cmowforth (2008-05-29 09:54:08)