time_range_helper.rb 487 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2023 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 'week'
  13. from += value.weeks
  14. when 'month'
  15. from += value.months
  16. when 'year'
  17. from += value.years
  18. end
  19. from
  20. end
  21. end