Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UTC with Sequel?

Tags:

ruby

sequel

I'd like to not store times in my local timezone, but Sequel is making it really tough on me. I can set them to UTC before I put them in there (a bit of a pain), but then when I take them back out it assumes that they are local dates and then they are all 8 hours in the future. Is this something that hasn't been implemented yet? And if so, are there any workarounds? Thanks!

like image 638
Phil Kulak Avatar asked Jul 11 '09 21:07

Phil Kulak


2 Answers

This is a bit outdated at this point but I believe the best solution here has changed since the original answer was posted. If you set

Sequel.default_timezone = :utc

sequel will treat all times as UTC and wont exhibit the behavior described in the question.

Find more info at http://sequel.jeremyevans.net/rdoc/classes/Sequel/Timezones.html

like image 164
Michael Wasser Avatar answered Nov 05 '22 00:11

Michael Wasser


Just had a very similar issue myself.

This information has been taken from the Sequel RDoc

Sequel can use either Time or DateTime for times returned from the database. It defaults to Time. To change it to DateTime, use:

Sequel.datetime_class = DateTime

Also make sure your not storing the timezone information in your database. I'm using Postgres and the column type is timestamp without time zone.

This should result in the displayed Date/Time being in UTC. It has worked for me when passing in a Date/Time of 2009-07-13T03:22:53Z the result is displayed as 2009-07-13T03:22:53+00:00

like image 23
Luke Antins Avatar answered Nov 05 '22 02:11

Luke Antins