Module: TimeHelper

Instance Method Summary collapse

Instance Method Details

#cron_with_zone(raw_cron:, forced_timezone: Rails.application.config.time_zone) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/time_helper.rb', line 19

def cron_with_zone(
  raw_cron:,
  forced_timezone: Rails.application.config.time_zone
)
  fugit_cron = Fugit::Cron.parse(raw_cron)
  return raw_cron unless fugit_cron

  if fugit_cron.zone
    cron_without_zone = raw_cron.gsub(fugit_cron.zone, '')
    cron_without_zone + " #{forced_timezone}"
  else
    raw_cron + " #{forced_timezone}"
  end
end

#destructure_seconds(seconds: 0) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/time_helper.rb', line 2

def destructure_seconds(
  seconds: 0
)
  return {} unless seconds

  interval_to_choose = %w[year month week day hours minute second].find do |interval|
    (seconds % 1.send(interval).to_i).zero?
  end

  count = seconds / 1.send(interval_to_choose).to_i

  {
    count: count,
    interval: interval_to_choose
  }
end