On Mon, Nov 30, 2020 at 3:11 PM J. Lewis Muir <[email protected]> wrote:

> 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.
>

In spite of the warning, does Sequel submit the correct SQL to the database
(time in America/Chicago time zone)?  Because the mysql2 adapter does its
own time conversions, the application_timezone setting doesn't affect that,
but maybe we can add a feature to override the timezone passed to the
mysql2 driver is :local or :utc even if the Sequel timezone setting is
different.

Thanks,
Jeremy

-- 
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/CADGZSSeujVS3GgUn9LMSa2R6ztGLP5iZ_7XL93_mJDh%3D0BZbYw%40mail.gmail.com.

Reply via email to