I'm trying to run some reports with a cron job that are Timezone specific. I've read that setting Time.zone is a bad idea since it alters the Time.zone for other requests on the same thread. My alternative was to use in_time_zone
on a Time object but that is causing issues too. I'm trying to query records between a certain start and end time for a given time zone. However, when I use strptime
and then call in_time_zone
it completely alters the day in reference to UTC. I simply want the day in CST. Here is my code:
Time.strptime("06/26/2020", "%m/%d/%Y").beginning_of_day #this outputs the beginning of the day in UTC.
Time.strptime("06/26/2020", "%m/%d/%Y").in_time_zone("Central Time (US & Canada)").beginning_of_day #this outputs the 25th at 19:00 hours.
Here is the link I found that stated setting Time.zone outside of the application.rb
wasn't thread safe.
https://rubyinrails.com/2018/02/25/rails-do-not-set-time-zone-to-avoid-time-zone-issues/