Last active
August 29, 2015 14:05
-
-
Save zentooo/c74de9af810ec760417f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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