Getting time when cron job is invoked
kazhian opened this issue · 3 comments
kazhian commented
I created a cron job which generates a report. In report i want to include the job time, instead of calculating current time.
So, I passed job parameter to the code block. When I use job.last_time it gives me the time. But how to find the time zone from it?
Rufus::Scheduler.new.cron '* * * * *' do |job|
puts "#{job.last_time.zone}"
end
But the zone is printed as 'Etc - UTC'. Why it displays two zones?
jmettraux commented
Hello,
"Etc" is not a time zone, it's an area. See also the list of database timezones.
Closing since it's not a Rufus-Scheduler issue but it's related to how your system is set.
Best regards.
jmettraux commented
Other ways to play with it:
require 'rufus-scheduler'
s = Rufus::Scheduler.new
s.cron '*/3 * * * * *' do |job|
puts "-"
puts "#{job.last_time}"
puts "#{job.last_time.zone}"
puts "#{job.last_time.zone.name}"
puts "#{job.last_time.zone.abbreviation}"
puts "#{job.last_time.zone.canonical_zone}"
puts "#{job.last_time.zone.canonical_identifier}"
puts "#{job.last_time.zone.friendly_identifier}"
puts "#{job.last_time.to_t}"
puts "#{job.last_time.to_t.zone}"
end
s.join
kazhian commented
Thank you !!