future_past.rb 749 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Validations::ObjectManager::AttributeValidator::FuturePast < Validations::ObjectManager::AttributeValidator::Backend
  3. def validate
  4. return if value.blank?
  5. return if irrelevant_attribute?
  6. validate_past
  7. validate_future
  8. end
  9. private
  10. def irrelevant_attribute?
  11. attribute.data_type != 'datetime'.freeze
  12. end
  13. def validate_past
  14. return if attribute.data_option[:past]
  15. return if !value.past?
  16. invalid_because_attribute(__('does not allow past dates'))
  17. end
  18. def validate_future
  19. return if attribute.data_option[:future]
  20. return if !value.future?
  21. invalid_because_attribute(__('does not allow future dates'))
  22. end
  23. end