Hi all,

I've recently moved an app to Heroku, using one of their Postgres
databases. The times coming out of that database were -8 hrs, so I started
having a look and it seems the times were being saved with the timezone
even though the column type is "timestamp without time zone".

It also appears that the database timezone is set to localtime, which means
its localtime of -8hrs to UTC, that I can't change that, and that Sequel
believes those times to be UTC so I'm getting the wrong times in my app.

I'm running a postgres database locally using the same migrations and code
and it works the way I want it to. I can't (or haven't found a way
to) change the settings for the Heroku server, so I'm looking for a
solution with Sequel.

Here is some relevant code and info:

In the migration:

    DateTime :created_at, null: false, default: Sequel::CURRENT_TIMESTAMP

Before the database is initialised:

    Sequel.default_timezone = :utc

Getting the record via the sequel console:

    t = Action[105]
    => #<Action @values={:id=>105, :created_at=>2012-02-21 15:15:42 UTC,
:description=>"This is a test", :owner=>1 }

    t.created_at.class
    => Time
    >> t.created_at.zone
    => "UTC"
    DB.timezone
    => :utc

In the postgres database, using the heroku sql console:

    select * from actions where id = 105;
    => | 105 | 2012-02-21 15:15:42 -0800 | This is a test |     1 |

    select current_setting('timezone');
    => localtime
    set timezone = 'UTC';
    select current_setting('timezone');
    => localtime  # nothing changed

And this is how the sql console reports the schema for that column:
    => | created_at  | timestamp without time zone | not null now()

I also set the TZ env variable to UTC.

I'm a bit confused now, with all the different settings and libraries
interacting, and if there is a way to get Sequel to either recognise the
timezone or set the default to use a timezone that would probably be best.
My "plan b" is to save the times as two separate columns, seconds from
midnight as an integer, and the timezone.

Any help or insight would be much appreciated.


Regards,
Iain

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to