That helped me. Thanks a lot. Awaiting a new release.
On Thursday, August 11, 2016 at 8:46:40 PM UTC+5:30, Jeremy Evans wrote:
>
> On Thursday, August 11, 2016 at 8:02:32 AM UTC-7, Jeremy Evans wrote:
>>
>> On Thursday, August 11, 2016 at 6:46:09 AM UTC-7, Satyanarayana Gandham
>> wrote:
>>>
>>> Hi,
>>>
>>> Recently, I tried to migrate from mysql gem to mysql2 gem. One different
>>> behavior I noticed is the Time(only_time) column. For the saved object, the
>>> value is a Time object with date pointing to "2000-01-01" whereas for the
>>> new object, the value is a Time object with date pointing to current date.
>>> I didn't encounter this when worked with mysql gem(both the cases, it is
>>> current date).
>>>
>>> Is there a way I can make the time object to be of the same date of new
>>> and saved objects?
>>>
>>> Here is my output from racksh:
>>>
>>> [1] pry(main)> s = Slot.first
>>> => #<Slot @values={:id=>342, :start=>2000-01-01 09:00:00 +0000,
>>> :finish=>2000-01-01 17:00:00 +0000}>
>>> [2] pry(main)> s_new = Slot.new(start: "09:00:00")
>>> => #<Slot @values={:start=>2016-08-11 09:00:00 +0000}>
>>> [3] pry(main)> s_new.start
>>> => 2016-08-11 09:00:00 +0000
>>> [4] pry(main)> s.start
>>> => 2000-01-01 09:00:00 +0000
>>>
>>> This is my migration:
>>>
>>> Sequel.migration do
>>> create_table(:slots) do
>>> ...
>>> Time :start, only_time: true
>>> ...
>>> end
>>> end
>>>
>>
>> Ruby doesn't have an object that holds a time without a date. The
>> Time/DateTime classes both only support times with dates. So you have to
>> pick a date to use.
>>
>> Sequel's default is to use the current date, since I think that makes the
>> most sense. The mysql2 driver apparently picks 2000-01-01 as the date (
>> https://github.com/brianmario/mysql2/blob/08f21e8ed3f82dc64ddd76c71c8530502f19212b/ext/mysql2/result.c#L1051).
>>
>> I do not know why they picked that date, maybe for compatibility with
>> other products?
>>
>> I think the best way to fix this is probably adding support for something
>> like:
>>
>> Sequel::SQLTime.date = Date.new(2000)
>>
>> which would allow you to set the date used for SQLTime instances. I'll
>> add that before the next release.
>>
>
> Added:
> https://github.com/jeremyevans/sequel/commit/537f90ef7b7873bf78788e7df45e3c0310667489
>
> 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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.