On Thu, Dec 3, 2020 at 4:02 PM J. Lewis Muir <[email protected]> wrote:

> On Thursday, December 3, 2020 at 1:33:42 PM UTC-6 Jeremy Evans wrote:
>
>> On Thu, Dec 3, 2020 at 11:03 AM J. Lewis Muir wrote:
>>
>>> On Thursday, December 3, 2020 at 12:00:20 AM UTC-6 Jeremy Evans wrote:
>>>
>>>> If you can use Ruby 2.0, you should be able to easily use the mysql
>>>> gem.  Current Sequel runs fine on Ruby 2.0.  You will have to switch to
>>>> Sequel.datetime_class = DateTime, though, because timezone support was not
>>>> added to Time until Ruby 2.6.
>>>>
>>>
>>> I understand that time zone support was only added to Time in Ruby 2.6,
>>> but for Ruby 2.0, I don't understand how DateTime is able to handle time
>>> zones any better than Time.  I don't see any support for named time zones
>>> in Time nor DateTime as of Ruby 2.0; I just see support for a UTC offset.
>>> So, I'm not understanding the need for Sequel.datetime_class = DateTime.
>>> Could you explain?
>>>
>>
>> Before Ruby 2.6, Time didn't handle timezones, and you can't take an
>> existing Time instance and convert it to a new timezone offset (unlike with
>> DateTime).  You could only convert it from local to utc or vice versa.
>>
>> Before Ruby 2.2, Time cannot even deal with parsed times not in the local
>> zone:
>>
>> $ruby21  -rtime -e 'p Time.parse("2020-10-20 10:20:30-03:00")'
>> 2020-10-20 06:20:30 -0700
>> $ ruby22  -rtime -e 'p Time.parse("2020-10-20 10:20:30-03:00")'
>> 2020-10-20 10:20:30 -0300
>>
>> DateTime itself doesn't handle timezones in any version, but Sequel can
>> use TZInfo to figure out the correct offset, and use
>> DateTime's offset support to set the offset correctly.  Sequel can't do
>> that with Time, since Time doesn't have support for it.
>>
>
> Thank you for the explanation!  I looked at Sequel's
> lib/sequel/timezones.rb, and I see it using DateTime#new_offset.  I had no
> idea this would work in Ruby 2.0 because that instance method does not
> exist in the docs:
>
> * https://ruby-doc.org/stdlib-2.0.0/libdoc/date/rdoc/DateTime.html
> * https://ruby-doc.org/stdlib-2.0.0/libdoc/date/rdoc/Date.html
>
> But it's listed in "DateTime.instance_methods", and "ri
> DateTime.new_offset" knows about it.  Looking at the Ruby source, if I'm
> reading it right, that method is private in Ruby 2.0:
>
>   https://github.com/ruby/ruby/blob/ruby_2_0_0/ext/date/date_core.c#L9523
>
>
That's Date#new_offset, not DateTime#new_offset.  See
https://github.com/ruby/ruby/blob/ruby_2_0_0/ext/date/date_core.c#L9629

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/CADGZSSfw_RCT7MokSGZ6wmGiMVLjFJhnyD%3D3%2BaX9jsCh7%2BsWyg%40mail.gmail.com.

Reply via email to