Topic: adding time to validates_timeliness

Does anybody know how to add a specific amount of time to a passed method using the validates_timeliness gem?

Here is what I have (which doesn't work):

I want the enddate to be restricted to 1 year from the startdate.

validates_date   :enddate, :on_or_before => lambda {(Date.strptime(:startdate) >> 12).to_s}

Can't seem to pass in :startdate... if I replace startdate with something like '2011-06-04'... then it works fine, but I need to make that more dynamic.

Your help would be greatly appreciated.... thanks! smile

Re: adding time to validates_timeliness

The lambda can take an optional argument that references the model object, so you can do:

validates_date :enddate, :on_or_before => lambda { |r| r.startdate + 1.year }

You might want to add an :unless option too that skips the validation if startdate is blank.

Rob Anderton

Re: adding time to validates_timeliness

thank you Rob.  that worked out perfectly!