2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-03-14 10:06:49 +00:00
|
|
|
class ObjectManager::Attribute::Validation::FuturePast < ObjectManager::Attribute::Validation::Backend
|
2019-03-13 23:51:22 +00:00
|
|
|
|
|
|
|
def validate
|
|
|
|
return if value.blank?
|
|
|
|
return if irrelevant_attribute?
|
|
|
|
|
|
|
|
validate_past
|
|
|
|
validate_future
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def irrelevant_attribute?
|
2019-03-14 10:06:49 +00:00
|
|
|
attribute.data_type != 'datetime'.freeze
|
2019-03-13 23:51:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate_past
|
|
|
|
return if attribute.data_option[:past]
|
|
|
|
return if !value.past?
|
|
|
|
|
|
|
|
invalid_because_attribute('does not allow past dates.')
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_future
|
|
|
|
return if attribute.data_option[:future]
|
|
|
|
return if !value.future?
|
|
|
|
|
|
|
|
invalid_because_attribute('does not allow future dates.')
|
|
|
|
end
|
|
|
|
end
|