Skip to content

Instantly share code, notes, and snippets.

@davidphasson
Created April 7, 2009 23:05
Show Gist options
  • Save davidphasson/91528 to your computer and use it in GitHub Desktop.
Save davidphasson/91528 to your computer and use it in GitHub Desktop.
# Time specifications:
validates_each :assembly_time2 do |record, attr, value|
next if value.nil?
# Leave this up to other validation
next if record.assembly_time1.nil?
if value < ( record.assembly_time1 + 1.hour + 15.minutes )
record.errors.add attr, "must allow for at least one hour assembly and 15 minute break"
end
end
validates_each :assembly_time3 do |record, attr, value|
next if value.nil?
# Leave this up to other validation
next if record.assembly_time2.nil?
if value < ( record.assembly_time2 + 1.hour + 15.minutes )
record.errors.add attr, "must allow for at least one hour assembly and 15 minute break"
end
end
validates_each :assembly_time1 do |record, attr, value|
next if value.nil?
# Must be later than 9:30
if (value.hour < 9) || (value.hour == 9 && value.min < 30 )
record.errors.add attr, "must be no earlier than 9:30am"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment