aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/jobs/timezone_dependent_job.rb
blob: 41f473d533ca916f7fcde2252739b373e561e635 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

require_relative "../support/job_buffer"

class TimezoneDependentJob < ActiveJob::Base
  def perform(now)
    now = now.in_time_zone
    new_year = localtime(2018, 1, 1)

    if now >= new_year
      JobBuffer.add("Happy New Year!")
    else
      JobBuffer.add("Just #{(new_year - now).div(3600)} hours to go")
    end
  end

  private

    def localtime(*args)
      Time.zone ? Time.zone.local(*args) : Time.utc(*args)
    end
end