Skip to content

Instantly share code, notes, and snippets.

@zentooo
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zentooo/c74de9af810ec760417f to your computer and use it in GitHub Desktop.
Save zentooo/c74de9af810ec760417f to your computer and use it in GitHub Desktop.
def check_date
errors.add(:start_date, '開始時刻を入力してください') if start_date.nil?
errors.add(:end_date, '終了日を入力してください') if end_date.nil?
return unless errors.empty?
check_start_date_before_end_date(start_date, end_date)
check_start_date_and_end_date_gap(start_date, end_date)
end
def check_start_date_before_end_date(start_date, end_date)
return if start_date <= end_date
errors.add(:start_date, '開始時刻は終了時刻より前の時間を設定してください')
errors.add(:end_date, '開始時刻は終了時刻より前の時間を設定してください')
end
def check_start_date_and_end_date_gap(start_date, end_date)
return if end_date - start_date > 1.hour
errors.add(:start_date, '終了時刻は開始時刻より1時間以上の間を空けて設定してください')
errors.add(:end_date, '終了時刻は開始時刻より1時間以上の間を空けて設定してください')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment