On Fri, Dec 4, 2020 at 10:13 AM J. Lewis Muir <[email protected]> wrote:
> Using Sequel with the mysql2 adapter, I set "Sequel.datetime_class =
> DateTime", yet I'm getting back a Time object from a query; why?
>
> For example, in the following, the class of result[:start_time_dt] ends up
> being Time, not DateTime:
>
> ----
> Sequel.single_threaded = true
> Sequel.application_timezone = :utc
> Sequel.database_timezone = :local
> Sequel.typecast_timezone = :local
> Sequel.datetime_class = DateTime
>
> events = DB[:mysql2_datetime_class_test_events]
> start_time = DateTime.parse('2020-12-01 08:00:00 -06:00').new_offset(0)
> id = events.insert(start_time_dt: start_time)
> result = events.where(id: id).first
> result[:start_time_dt].class
> ----
>
> Environment:
> * Ruby 2.0.0p648
> * Sequel 5.39.0
> * Mysql2 0.5.3
> * MariaDB Connector/C 3.1.11
>
> I saw the sequel-talk conversation "Time object returned from DB although
> Sequel.datetime_class = DateTime" from 2012
>
> https://groups.google.com/g/sequel-talk/c/ybfJsUxM4oM/m/IIcK_D9X-jEJ
>
> but I was half hoping that the issue had been fixed since then.
>
As in your previous issue, the mysql2 driver does the parsing in this case
and Sequel does not have control. If you would like this, you'll have to
submit an issue or pull request to mysql2 to support using DateTime instead
of Time. However, considering that DateTime is now considered deprecated (
https://github.com/ruby/date/commit/58ca6e6a3ee20c72a77266e0f74920b12a06ee9d),
I think it is unlikely they would be willing to accept it.
Similar to the previous issue, the mysql adapter recognizes and supports
the Sequel.datetime_class setting, as Sequel does the parsing in that case.
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/CADGZSScp9bUEOiaR-f_xbUWkmLsqkxmm_x7R-a%2BLHQ6Ap8xUyg%40mail.gmail.com.