date.rb 613 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::ApplyValue::Date < FormUpdater::ApplyValue::Base
  3. def can_handle_field?(field:, field_attribute:)
  4. field_attribute&.data_type == 'date'
  5. end
  6. def map_value(field:, config:)
  7. result[field][:value] = resolve_time(config:)
  8. end
  9. protected
  10. def resolve_time(config:)
  11. if config['operator'] != 'relative'
  12. return config['value']
  13. end
  14. format_time TimeRangeHelper.relative(range: config['range'], value: config['value'])
  15. end
  16. def format_time(time)
  17. time.strftime('%Y-%m-%d')
  18. end
  19. end