Liam Morley
2008-Sep-07 05:30 UTC
time_select and config.time_zone, handling cases when a timezone isn''t applicable
I''m running into an issue where I''d like to use timezones in my application, but I''d also like to use times in places where timezone is not applicable. For example, I have a Store model, and I need to track what time of day the store opens. I''m using time_select to edit this field in my form, and when I submit the form with 0 hours, it goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, it reads this as 05:00:00, and so the displayed number for hours is always 5 more than I entered. Seems to me that the translation to/from utc is only occurring in one direction. I''m posting this here on the advice of bitsweat from irc. If anybody wants more information or a pastie of sorts, let me know. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Geoff B
2008-Sep-07 21:21 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
HI Liam, I''d need a bit more info (rails version, config.time_zone setting, store opening time column type, and exactly what you''re doing when you "refresh the form") to determine whether this is a framework issue or an application design issue. Feel free to contact me directly if you like. Geoff On Sep 7, 12:30 am, Liam Morley <imo...@gmail.com> wrote:> I''m running into an issue where I''d like to use timezones in my > application, but I''d also like to use times in places where timezone > is not applicable. For example, I have a Store model, and I need to > track what time of day the store opens. I''m using time_select to edit > this field in my form, and when I submit the form with 0 hours, it > goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, > it reads this as 05:00:00, and so the displayed number for hours is > always 5 more than I entered. Seems to me that the translation to/from > utc is only occurring in one direction. > > I''m posting this here on the advice of bitsweat from irc. If anybody > wants more information or a pastie of sorts, let me know.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
John Trupiano
2008-Sep-10 19:11 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
Hey Geoff, Liam, I''m running into the same issue, and it''s very simple to create an example. 1) $> rails time_select_problem 2) $> cd time_select_problem 3) $> ruby script/generate scaffold stores name:string opens:time 4) Edit config/environment.rb, set config.time_zone = ''Eastern Time (US & Canada)'' and config.active_record.default_timezone = :utc 5) $> rake db:create db:migrate 6) $> ruby script/server 7) Navigate to localhost:3000/stores/new 8) Create one, setting the time to 10:00 AM 9) After creation, go to show/edit. You''ll see that the time is displayed in both as 3:00 PM. I can understand ''show'' failing, as we haven''t directly converted to this user''s timezone. But edit _should_ show up correctly. If you check the database, you''ll see that it was stored as 3:00 PM UTC. The conversion is made from EST to UTC. But when we pull it back out using either time_select or datetime_select, the conversion back is not made. Does this better illustrate the problem? Is there a flaw in my process? Am I missing something here? It just doesn''t seem right that I select 10:00 in the time slot, and then when I edit it with the same form, it shows something else! -John On Sep 7, 5:21 pm, Geoff B <gbues...@gmail.com> wrote:> HI Liam, > > I''d need a bit more info (rails version, config.time_zone setting, > store opening time column type, and exactly what you''re doing when you > "refresh the form") to determine whether this is a framework issue or > an application design issue. > > Feel free to contact me directly if you like. > > Geoff > > On Sep 7, 12:30 am, Liam Morley <imo...@gmail.com> wrote: > > > I''m running into an issue where I''d like to use timezones in my > > application, but I''d also like to use times in places where timezone > > is not applicable. For example, I have a Store model, and I need to > > track what time of day the store opens. I''m using time_select to edit > > this field in my form, and when I submit the form with 0 hours, it > > goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, > > it reads this as 05:00:00, and so the displayed number for hours is > > always 5 more than I entered. Seems to me that the translation to/from > > utc is only occurring in one direction. > > > I''m posting this here on the advice of bitsweat from irc. If anybody > > wants more information or a pastie of sorts, let me know. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Geoff B
2008-Sep-10 22:50 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
Hi John, We figured out the issue was the combination of time-only columns and multiparameter attributes -- AR::Base#instantiate_time_object is currently doing a time zone conversion for time-only columns, but it shouldn''t be. I''ll try to pull in a fix for this in soon (should be simple, we just need to add a check in #instantiate_time_object for the column type), but in the meantime, this will work: class Store def self.skip_time_zone_conversion_for_attributes [:opens] end end Geoff On Sep 10, 2:11 pm, John Trupiano <jtrupi...@gmail.com> wrote:> Hey Geoff, Liam, > > I''m running into the same issue, and it''s very simple to create an > example. > > 1) $> rails time_select_problem > 2) $> cd time_select_problem > 3) $> ruby script/generate scaffold stores name:string opens:time > 4) Edit config/environment.rb, set config.time_zone = ''Eastern Time > (US & Canada)'' and config.active_record.default_timezone = :utc > 5) $> rake db:create db:migrate > 6) $> ruby script/server > 7) Navigate to localhost:3000/stores/new > 8) Create one, setting the time to 10:00 AM > 9) After creation, go to show/edit. You''ll see that the time is > displayed in both as 3:00 PM. I can understand ''show'' failing, as we > haven''t directly converted to this user''s timezone. But edit _should_ > show up correctly. If you check the database, you''ll see that it was > stored as 3:00 PM UTC. The conversion is made from EST to UTC. But > when we pull it back out using either time_select or datetime_select, > the conversion back is not made. > > Does this better illustrate the problem? Is there a flaw in my > process? Am I missing something here? It just doesn''t seem right > that I select 10:00 in the time slot, and then when I edit it with the > same form, it shows something else! > > -John > > On Sep 7, 5:21 pm, Geoff B <gbues...@gmail.com> wrote: > > > HI Liam, > > > I''d need a bit more info (rails version, config.time_zone setting, > > store opening time column type, and exactly what you''re doing when you > > "refresh the form") to determine whether this is a framework issue or > > an application design issue. > > > Feel free to contact me directly if you like. > > > Geoff > > > On Sep 7, 12:30 am, Liam Morley <imo...@gmail.com> wrote: > > > > I''m running into an issue where I''d like to use timezones in my > > > application, but I''d also like to use times in places where timezone > > > is not applicable. For example, I have a Store model, and I need to > > > track what time of day the store opens. I''m using time_select to edit > > > this field in my form, and when I submit the form with 0 hours, it > > > goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, > > > it reads this as 05:00:00, and so the displayed number for hours is > > > always 5 more than I entered. Seems to me that the translation to/from > > > utc is only occurring in one direction. > > > > I''m posting this here on the advice of bitsweat from irc. If anybody > > > wants more information or a pastie of sorts, let me know.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
John Trupiano
2008-Sep-10 23:11 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
Excellent Geoff! That does the trick (and is cleaner than the massaging I was doing at the controller level in the meantime). I figured it would be a very straightforward adjustment in rails (the long-term fix, that is). -John On Sep 10, 6:50 pm, Geoff B <gbues...@gmail.com> wrote:> Hi John, > > We figured out the issue was the combination of time-only columns and > multiparameter attributes -- AR::Base#instantiate_time_object is > currently doing a time zone conversion for time-only columns, but it > shouldn''t be. > > I''ll try to pull in a fix for this in soon (should be simple, we just > need to add a check in #instantiate_time_object for the column type), > but in the meantime, this will work: > > class Store > def self.skip_time_zone_conversion_for_attributes > [:opens] > end > end > > Geoff > > On Sep 10, 2:11 pm, John Trupiano <jtrupi...@gmail.com> wrote: > > > Hey Geoff, Liam, > > > I''m running into the same issue, and it''s very simple to create an > > example. > > > 1) $> rails time_select_problem > > 2) $> cd time_select_problem > > 3) $> ruby script/generate scaffold stores name:string opens:time > > 4) Edit config/environment.rb, set config.time_zone = ''Eastern Time > > (US & Canada)'' and config.active_record.default_timezone = :utc > > 5) $> rake db:create db:migrate > > 6) $> ruby script/server > > 7) Navigate to localhost:3000/stores/new > > 8) Create one, setting the time to 10:00 AM > > 9) After creation, go to show/edit. You''ll see that the time is > > displayed in both as 3:00 PM. I can understand ''show'' failing, as we > > haven''t directly converted to this user''s timezone. But edit _should_ > > show up correctly. If you check the database, you''ll see that it was > > stored as 3:00 PM UTC. The conversion is made from EST to UTC. But > > when we pull it back out using either time_select or datetime_select, > > the conversion back is not made. > > > Does this better illustrate the problem? Is there a flaw in my > > process? Am I missing something here? It just doesn''t seem right > > that I select 10:00 in the time slot, and then when I edit it with the > > same form, it shows something else! > > > -John > > > On Sep 7, 5:21 pm, Geoff B <gbues...@gmail.com> wrote: > > > > HI Liam, > > > > I''d need a bit more info (rails version, config.time_zone setting, > > > store opening time column type, and exactly what you''re doing when you > > > "refresh the form") to determine whether this is a framework issue or > > > an application design issue. > > > > Feel free to contact me directly if you like. > > > > Geoff > > > > On Sep 7, 12:30 am, Liam Morley <imo...@gmail.com> wrote: > > > > > I''m running into an issue where I''d like to use timezones in my > > > > application, but I''d also like to use times in places where timezone > > > > is not applicable. For example, I have a Store model, and I need to > > > > track what time of day the store opens. I''m using time_select to edit > > > > this field in my form, and when I submit the form with 0 hours, it > > > > goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, > > > > it reads this as 05:00:00, and so the displayed number for hours is > > > > always 5 more than I entered. Seems to me that the translation to/from > > > > utc is only occurring in one direction. > > > > > I''m posting this here on the advice of bitsweat from irc. If anybody > > > > wants more information or a pastie of sorts, let me know. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Michael Koziarski
2008-Sep-11 09:10 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
On Thu, Sep 11, 2008 at 1:11 AM, John Trupiano <jtrupiano@gmail.com> wrote:> > Excellent Geoff! That does the trick (and is cleaner than the > massaging I was doing at the controller level in the meantime). > > I figured it would be a very straightforward adjustment in rails (the > long-term fix, that is).Can you guys create a lighthouse ticket for this and assign it to me or geoff, it''d be a shame to ship a release with this bug because this dropped off the radar.> -John > > On Sep 10, 6:50 pm, Geoff B <gbues...@gmail.com> wrote: >> Hi John, >> >> We figured out the issue was the combination of time-only columns and >> multiparameter attributes -- AR::Base#instantiate_time_object is >> currently doing a time zone conversion for time-only columns, but it >> shouldn''t be. >> >> I''ll try to pull in a fix for this in soon (should be simple, we just >> need to add a check in #instantiate_time_object for the column type), >> but in the meantime, this will work: >> >> class Store >> def self.skip_time_zone_conversion_for_attributes >> [:opens] >> end >> end >> >> Geoff >> >> On Sep 10, 2:11 pm, John Trupiano <jtrupi...@gmail.com> wrote: >> >> > Hey Geoff, Liam, >> >> > I''m running into the same issue, and it''s very simple to create an >> > example. >> >> > 1) $> rails time_select_problem >> > 2) $> cd time_select_problem >> > 3) $> ruby script/generate scaffold stores name:string opens:time >> > 4) Edit config/environment.rb, set config.time_zone = ''Eastern Time >> > (US & Canada)'' and config.active_record.default_timezone = :utc >> > 5) $> rake db:create db:migrate >> > 6) $> ruby script/server >> > 7) Navigate to localhost:3000/stores/new >> > 8) Create one, setting the time to 10:00 AM >> > 9) After creation, go to show/edit. You''ll see that the time is >> > displayed in both as 3:00 PM. I can understand ''show'' failing, as we >> > haven''t directly converted to this user''s timezone. But edit _should_ >> > show up correctly. If you check the database, you''ll see that it was >> > stored as 3:00 PM UTC. The conversion is made from EST to UTC. But >> > when we pull it back out using either time_select or datetime_select, >> > the conversion back is not made. >> >> > Does this better illustrate the problem? Is there a flaw in my >> > process? Am I missing something here? It just doesn''t seem right >> > that I select 10:00 in the time slot, and then when I edit it with the >> > same form, it shows something else! >> >> > -John >> >> > On Sep 7, 5:21 pm, Geoff B <gbues...@gmail.com> wrote: >> >> > > HI Liam, >> >> > > I''d need a bit more info (rails version, config.time_zone setting, >> > > store opening time column type, and exactly what you''re doing when you >> > > "refresh the form") to determine whether this is a framework issue or >> > > an application design issue. >> >> > > Feel free to contact me directly if you like. >> >> > > Geoff >> >> > > On Sep 7, 12:30 am, Liam Morley <imo...@gmail.com> wrote: >> >> > > > I''m running into an issue where I''d like to use timezones in my >> > > > application, but I''d also like to use times in places where timezone >> > > > is not applicable. For example, I have a Store model, and I need to >> > > > track what time of day the store opens. I''m using time_select to edit >> > > > this field in my form, and when I submit the form with 0 hours, it >> > > > goes in the db as 05:00:00 (I''m in EST). Then when I refresh the form, >> > > > it reads this as 05:00:00, and so the displayed number for hours is >> > > > always 5 more than I entered. Seems to me that the translation to/from >> > > > utc is only occurring in one direction. >> >> > > > I''m posting this here on the advice of bitsweat from irc. If anybody >> > > > wants more information or a pastie of sorts, let me know. >> >> > > >-- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Geoff B
2008-Sep-11 23:28 UTC
Re: time_select and config.time_zone, handling cases when a timezone isn''t applicable
On Sep 11, 4:10 am, "Michael Koziarski" <mich...@koziarski.com> wrote:> Can you guys create a lighthouse ticket for this and assign it to me > or geoff, it''d be a shame to ship a release with this bug because this > dropped off the radar.Ticket opened: http://rails.lighthouseapp.com/projects/8994/tickets/1030-multiparameter-attributes-incorrectly-do-time-zone-conversion-on-time-only-columns I''ll pull in a fix for this in the next couple of days. Probably should be merged into 2-1-stable as well. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---