On Thursday, November 26, 2020 at 10:07:21 PM UTC-6 Jeremy Evans wrote:

> For UTC times in the application and local time in the database, where the 
> database uses a different timezone than the local machine, you probably 
> want to use the named_timezones extension:
>
> DB.extension :named_timezones
> Sequel.datetime_class = Time # unless you want DateTime
> Sequel.application_timezone = :utc
> DB.timezone = 'America/Chicago'
> t = Time.now
> # => 2020-11-26 19:54:18.473257155 -0800
> DB.get(Sequel.cast(t, Time))
> # SELECT CAST('2020-11-26 21:54:18.473257-0600' AS timestamptz) AS "v" 
> LIMIT 1
> # => 2020-11-27 03:54:18.473257 UTC
>

Thank you for the suggestion!  I tried it, but it seems that the mysql2 
adapter doesn't accept 'America/Chicago' for the database time zone because 
it emits the following warning:

----
/home/scratch/.gem/ruby/gems/sequel-5.38.0/lib/sequel/adapters/mysql2.rb:238: 
warning: :database_timezone option must be :utc or :local - defaulting to 
:local
----

Assuming Sequel passes DB.timezone to the mysql2 adapter via the adapter's 
:database_timezone option, this warning seems consistent with the mysql2 
adapter's Timezones documentation which says only :local and :utc are 
allowed values:

  https://www.rubydoc.info/gems/mysql2#timezones

I could, of course, set DB.timezone to :local, but I'm worried that that 
would mean the local timezone of the machine where the application is 
running rather than that of the machine where the database server is 
running which would obviously be incorrect when the two are not the same.

Lewis

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/49ec85e9-1983-469e-8df6-4eaf7ec33420n%40googlegroups.com.

Reply via email to