time_range_helper.rb 445 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class TimeRangeHelper
  3. def self.relative(from: Time.zone.now, range: 'day', value: 1)
  4. value = value.to_i
  5. case range
  6. when 'day'
  7. from += value.days
  8. when 'minute'
  9. from += value.minutes
  10. when 'hour'
  11. from += value.hours
  12. when 'month'
  13. from += value.months
  14. when 'year'
  15. from += value.years
  16. end
  17. from
  18. end
  19. end