1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/test/jobs/timezone_dependent_job.rb
Andrew White a9d1167b1f Add support for timezones to Active Job
Record what was the current timezone in effect when the job was
enqueued and then restore when the job is executed in same way
that the current locale is recorded and restored.
2018-02-22 14:14:42 +00:00

22 lines
465 B
Ruby

# 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