How do i query a database that stores times in utc, with ruby?
I am in the Central timezone (ENV['TZ'] = America/Chicago) but all my
MongoDB entries are stored in UTC format. So if I want to query entries
for all of yesterday, I have to overcompensate for the timezone:
tz = 5.hours
d1 = Date.yesterday.at_midnight + tz
d2 = d1 + 1.day
Entry.where(:created_at.gte => d1, :created_at.lt => d2)
I'm pretty sure that this is a major hack, but I'm not sure how to fix
this correctly? Should it be on the database end, or in the code. Are
there some reading resources that teach how to do this correctly?
No comments:
Post a Comment