What a pain in the ass. As I'm learning to use rails/ruby, one problem
that I didn't really anticipate was dealing with time zone issues.
However, given the nature of my new job and the need to be precise
about cutoff dates and times, precise times are necessary.
Enter the fact that Rails, utilizing ActiveSupport's TimeZone library,
does type casting of date and time information. This became a pretty
big issue for me as I was expected to take in some date/time
information set to EST. One thing that was implied yet never
explicitly stated was that MySQL would store everything as UTC -7
(since I'm in PST).
As such, in order to resolve this issue, I found I had to do the following:
1. Comment out config.time_zone in environment.rb. By default, this is
set to 'UTC'
2. In my rake task, while looping through a csv dataset, I set my
timezone to 'Eastern Time (US & Canada)'
3. I then had to parse the string data and then set it to its
appropriate timezone as such:
t = Time.zone.parse(row[1].to_s)
time_str = t.in_time_zone('Pacific Time (US & Canada)').to_s
One big thing I noticed as I grokked the intertubes for info was that
many examples would encourage this syntax to fit the appropriate
RDBMS: t.in_time_zone('Pacific Time (US & Canada)').to_s(:db) #notice
the :db flag
The ':db' flag ended up messing things up for me. As soon I removed
it, things worked peachy keen.