trabajo-afectivo/app/models/object_manager/attribute/validation/future_past.rb

33 lines
723 B
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class ObjectManager::Attribute::Validation::FuturePast < ObjectManager::Attribute::Validation::Backend
def validate
return if value.blank?
return if irrelevant_attribute?
validate_past
validate_future
end
private
def irrelevant_attribute?
attribute.data_type != 'datetime'.freeze
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