Like many, I''m building an application that will be used in various parts of the world. I see a TimeZone class that seems to work pretty well. The only problem is it doesn''t seem to support Daylight savings time. Does anyone have a good method for dealing with time which factors in Daylight savings? I noticed that BaseCamp seems to handle it so I''m guessing there is a way. --matt _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sep 8, 2005, at 9:16 AM, Matt Pantana wrote:> Like many, I''m building an application that will be used in various > parts of the world. I see a TimeZone class that seems to work > pretty well. The only problem is it doesn''t seem to support > Daylight savings time. > > Does anyone have a good method for dealing with time which factors > in Daylight savings? I noticed that BaseCamp seems to handle it so > I''m guessing there is a way.You might want to check out the tzinfo library on RubyForge. It''s pretty slick. Basecamp isn''t using it yet, but we may experiment with it in the near future. - Jamis
On Sep 8, 2005, at 12:37 PM, Jamis Buck wrote:> On Sep 8, 2005, at 9:16 AM, Matt Pantana wrote: > >> Like many, I''m building an application that will be used in various >> parts of the world. I see a TimeZone class that seems to work pretty >> well. The only problem is it doesn''t seem to support Daylight >> savings time. >> >> Does anyone have a good method for dealing with time which factors in >> Daylight savings? I noticed that BaseCamp seems to handle it so I''m >> guessing there is a way. > > You might want to check out the tzinfo library on RubyForge. It''s > pretty slick. Basecamp isn''t using it yet, but we may experiment with > it in the near future. > > - JamisI am also playing with tzinfo today (thanks to Jamis). I''m not completely done migrating my app to it, but so far it''s going very well. I''ve also got a set up to make it work correctly with AR aggregations (as TimeZone can). If you''re interested I can post it once I finish up (should be this afternoon). There is also Ruby/TZFile [1], but it looks less portable than tzinfo. Once Jamis mentioned tzinfo I stopped looking at tzfile so I didn''t give it a thorough [EVALUATION]. TZInfo looks like it''ll fit the bill. [1] http://cvs.m17n.org/~akr/ruby-tzfile/ -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com
Cool, thanks Jamis. On 9/8/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> > On Sep 8, 2005, at 9:16 AM, Matt Pantana wrote: > > > Like many, I''m building an application that will be used in various > > parts of the world. I see a TimeZone class that seems to work > > pretty well. The only problem is it doesn''t seem to support > > Daylight savings time. > > > > Does anyone have a good method for dealing with time which factors > > in Daylight savings? I noticed that BaseCamp seems to handle it so > > I''m guessing there is a way. > > You might want to check out the tzinfo library on RubyForge. It''s > pretty slick. Basecamp isn''t using it yet, but we may experiment with > it in the near future. > > - Jamis > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks Scott, I''d love to see it. One thing that concerns me with TZInfo is it''s depth (although I''m glad it is.) I''m counting 241 countries, many of which have upwards of 5 timezones. That could make for a massive dropdown. I guess you could have them select country first and then generate the zones for that country after the selection. But I''m wondering if a more gracefull balance b/w rails timezone select and the full listing in TZInfo can be found. --matt On 9/8/05, Scott Barron <scott-HDQKq3lYuGDk1uMJSBkQmQ@public.gmane.org> wrote:> > > On Sep 8, 2005, at 12:37 PM, Jamis Buck wrote: > > > On Sep 8, 2005, at 9:16 AM, Matt Pantana wrote: > > > >> Like many, I''m building an application that will be used in various > >> parts of the world. I see a TimeZone class that seems to work pretty > >> well. The only problem is it doesn''t seem to support Daylight > >> savings time. > >> > >> Does anyone have a good method for dealing with time which factors in > >> Daylight savings? I noticed that BaseCamp seems to handle it so I''m > >> guessing there is a way. > > > > You might want to check out the tzinfo library on RubyForge. It''s > > pretty slick. Basecamp isn''t using it yet, but we may experiment with > > it in the near future. > > > > - Jamis > > I am also playing with tzinfo today (thanks to Jamis). I''m not > completely done migrating my app to it, but so far it''s going very > well. I''ve also got a set up to make it work correctly with AR > aggregations (as TimeZone can). If you''re interested I can post it > once I finish up (should be this afternoon). > > There is also Ruby/TZFile [1], but it looks less portable than tzinfo. > Once Jamis mentioned tzinfo I stopped looking at tzfile so I didn''t > give it a thorough [EVALUATION]. TZInfo looks like it''ll fit the bill. > > [1] http://cvs.m17n.org/~akr/ruby-tzfile/ > > -- > Scott Barron > Lunchbox Software > http://lunchboxsoftware.com > http://lunchroom.lunchboxsoftware.com > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Sep 8, 2005, at 2:17 PM, Matt Pantana wrote:> Thanks Scott, I''d love to see it. One thing that concerns me with > TZInfo is it''s depth (although I''m glad it is.) I''m counting 241 > countries, many of which have upwards of 5 timezones. That could make > for a massive dropdown. I guess you could have them select country > first and then generate the zones for that country after the > selection. But I''m wondering if a more gracefull balance b/w rails > timezone select and the full listing in TZInfo can be found. > > --matt > >Cool. I just finished moving my application (it all seems to be working very well) and am doing a little write up of how I integrated TZInfo, I''ll post a link to it here in a bit. The number of time zones to select from is also on my mind, as I am using time_zone_select. I have integrated TZInfo into time_zone_select, but yeah it''s a large drop down. A trimming down of the entries would probablly be a good idea. Who wants to convert TimeZone.all into TZInfo country/zone names? ;) -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com
On Sep 8, 2005, at 12:24 PM, Scott Barron wrote:> On Sep 8, 2005, at 2:17 PM, Matt Pantana wrote: > > >> Thanks Scott, I''d love to see it. One thing that concerns me with >> TZInfo is it''s depth (although I''m glad it is.) I''m counting 241 >> countries, many of which have upwards of 5 timezones. That could >> make for a massive dropdown. I guess you could have them select >> country first and then generate the zones for that country after >> the selection. But I''m wondering if a more gracefull balance b/w >> rails timezone select and the full listing in TZInfo can be found. >> >> --matt >> >> >> > > Cool. I just finished moving my application (it all seems to be > working very well) and am doing a little write up of how I > integrated TZInfo, I''ll post a link to it here in a bit. > > The number of time zones to select from is also on my mind, as I am > using time_zone_select. I have integrated TZInfo into > time_zone_select, but yeah it''s a large drop down. A trimming down > of the entries would probablly be a good idea. Who wants to > convert TimeZone.all into TZInfo country/zone names? ;)A mapping from one to the other is on my to-do list, but if someone beats me to it I won''t hold it against them. :) - Jamis
On Sep 8, 2005, at 2:24 PM, Scott Barron wrote:> > On Sep 8, 2005, at 2:17 PM, Matt Pantana wrote: > >> Thanks Scott, I''d love to see it. One thing that concerns me with >> TZInfo is it''s depth (although I''m glad it is.) I''m counting 241 >> countries, many of which have upwards of 5 timezones. That could >> make for a massive dropdown. I guess you could have them select >> country first and then generate the zones for that country after the >> selection. But I''m wondering if a more gracefull balance b/w rails >> timezone select and the full listing in TZInfo can be found. >> >> --matt >> >> > > Cool. I just finished moving my application (it all seems to be > working very well) and am doing a little write up of how I integrated > TZInfo, I''ll post a link to it here in a bit. > > The number of time zones to select from is also on my mind, as I am > using time_zone_select. I have integrated TZInfo into > time_zone_select, but yeah it''s a large drop down. A trimming down of > the entries would probablly be a good idea. Who wants to convert > TimeZone.all into TZInfo country/zone names? ;) >I''ve posted a draft of my write up, linked here [1]. Questions, comments, suggestions always welcome. [1] http://lunchroom.lunchboxsoftware.com/articles/2005/09/08/zoning-out -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com
> Like many, I''m building an application that will be used in various parts ofthe world. I see a TimeZone class that seems to work pretty well. The only problem is it doesn''t seem to support Daylight savings time. Matt, I''m running MySQL and I''m using the following approach. 1. Load timezone information into the MySQL database * mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql 2. Set the default MySQL timezone to GMT * using default-time-zone=GMT 3. Set the default Rails timezone to GMT. * http://wiki.rubyonrails.com/rails/show/HowtoSetDefaultTimeZone 4. Get all users to specify their timezone when they create an account. 5. Anytime you need to retrieve a time, use mysql''s timezone convert command. e.g., SELECT CONVERT_TZ(now(), "GMT", "PST8PDT") You should also search the list archives - I seem to remember someone posting an information answer to the same question about 2-3 months ago. Tyler
Tyler Kovacs wrote:> 2. Set the default MySQL timezone to GMT > * using default-time-zone=GMT > 3. Set the default Rails timezone to GMT. > * http://wiki.rubyonrails.com/rails/show/HowtoSetDefaultTimeZoneI asked a similar question the other day, but am still searching for the best answer. Is there any equivalent way of setting my Rails app and DB (Postgres) to use the "Europe/London" timezone, independent of the local timezone of the server? I don''t require anything more than GMT and BST (British Summer Time), since this application relates to the UK only, and this will always be the case (it''s tied to a specific physical location). The reason I ask this is because during development, before I''d got as far as worrying about timezones, I developed my app on my local machine and was very pleasantly surprised to see it already taking care of BST time changes for me. I had expected all along that I would need to code this myself, but it''s now working perfectly here, and happened almost automatically. However, it will live on the Textdrive servers (USA) so the local timezone is not the same, which I guess means it doesn''t automatically take care of GMT/BST. I was really hoping I might be able to set something in my environment for Rails and Postgres to make it behave like the machine''s timezone was set to "Europe/London", as my local machine is. Does anyone know if this is possible? Or definitely not possible? (Might it even be easier to find a UK Rails host instead... I don''t know?) This is not my first time dealing with times in an application, but it''s the first time I''ve dealt with periods of time requiring critical synchronisation with each other (a booking system based on times), and I''m not entirely sure of the best way to proceed. I don''t mind coding the stuff myself if necessary, but if anyone else can offer insight into how they did it, that would be really helpful! Basically, I need to be able to ask the system "on this specified date, are we in GMT or BST", and the reason I''m at this crossroads is that it already seems to happen fantastically, automatically on my local Linux machine, and I''m not sure my implementation would be as good as that! It seems a shame not to use something that already works so well! Cheers, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
I am guessing that the reason it works fine on your development maching is that is it using local time and Linux is automatically adjusting local time for BST. You could probably test a TextDrive install to use GMT instead of local time but support for BST will need additional code. The question however remains where to get that code. If you were to use a UK host (of find a host willing to setup a machine on UK time) it would act just like your development maching. - Michael On 9/9/05, Dave Silvester <dave-AJqNGCqIqVQ7cdpDWioORw@public.gmane.org> wrote:> Tyler Kovacs wrote: > > 2. Set the default MySQL timezone to GMT > > * using default-time-zone=GMT > > 3. Set the default Rails timezone to GMT. > > * http://wiki.rubyonrails.com/rails/show/HowtoSetDefaultTimeZone > > I asked a similar question the other day, but am still searching for the best > answer. > > Is there any equivalent way of setting my Rails app and DB (Postgres) to use > the "Europe/London" timezone, independent of the local timezone of the server? > I don''t require anything more than GMT and BST (British Summer Time), since > this application relates to the UK only, and this will always be the case > (it''s tied to a specific physical location). > > The reason I ask this is because during development, before I''d got as far as > worrying about timezones, I developed my app on my local machine and was very > pleasantly surprised to see it already taking care of BST time changes for me. > I had expected all along that I would need to code this myself, but it''s now > working perfectly here, and happened almost automatically. > > However, it will live on the Textdrive servers (USA) so the local timezone is > not the same, which I guess means it doesn''t automatically take care of GMT/BST. > > I was really hoping I might be able to set something in my environment for > Rails and Postgres to make it behave like the machine''s timezone was set to > "Europe/London", as my local machine is. > > Does anyone know if this is possible? Or definitely not possible? (Might it > even be easier to find a UK Rails host instead... I don''t know?) > > This is not my first time dealing with times in an application, but it''s the > first time I''ve dealt with periods of time requiring critical synchronisation > with each other (a booking system based on times), and I''m not entirely sure > of the best way to proceed. > > I don''t mind coding the stuff myself if necessary, but if anyone else can > offer insight into how they did it, that would be really helpful! > > Basically, I need to be able to ask the system "on this specified date, are we > in GMT or BST", and the reason I''m at this crossroads is that it already seems > to happen fantastically, automatically on my local Linux machine, and I''m not > sure my implementation would be as good as that! It seems a shame not to use > something that already works so well! > > Cheers, > > ~Dave > > -- > > Dave Silvester > Rent-A-Monkey Website Development > Web: http://www.rentamonkey.com/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Sep 9, 2005, at 11:52 AM, Michael King wrote:> I am guessing that the reason it works fine on your development > maching is that is it using local time and Linux is automatically > adjusting local time for BST. > > You could probably test a TextDrive install to use GMT instead of > local time but support for BST will need additional code. The question > however remains where to get that code. > > If you were to use a UK host (of find a host willing to setup a > machine on UK time) it would act just like your development maching. > > - MichaelTextDrive''s shared servers are set to GMT, and this is how it should be. I posit that it is a bad idea to rely on the underlying system''s time zone for an application that depends on time. For some DST aware code for doing time manipulations, check out the recently released TZInfo [1] and my write up about using it in Rails [2]. [1] http://tzinfo.rubyforge.org/ [2] http://lunchroom.lunchboxsoftware.com/articles/2005/09/08/zoning-out -- Scott Barron Lunchbox Software http://lunchboxsoftware.com http://lunchroom.lunchboxsoftware.com
Michael King wrote:> I am guessing that the reason it works fine on your development > maching is that is it using local time and Linux is automatically > adjusting local time for BST.I''m certain that''s what''s happening - it''s very convenient! The best part is that it intrinsically knows which time zone to use for dates in the future... I was pretty surprised when that happened!> You could probably test a TextDrive install to use GMT instead of > local time but support for BST will need additional code. The question > however remains where to get that code.Perhaps I could just store a list of the necessary dates in the database for the next few hundred years (which will be beyond the lifetime of this application, I''m sure) and use that to calculate BST. It''s no problem to have the site running on UTC/GMT, so maybe that''s the route I''ll take. I was just thinking that following the DRY philosophy, it seems superfluous to rewrite stuff that is already working perfectly, regardless of what layer of the system facilitates it (since it''s coming from beyond Rails or Ruby)... I''m not sure? :-S> If you were to use a UK host (of find a host willing to setup a > machine on UK time) it would act just like your development maching.That is indeed the direction I may head in. This site will eventually be hosted on a dedicated server anyway, so it shouldn''t be a problem to have the machine running on a custom time zone. Or, perhaps I will just go with what I originally thought I would have to do (code this myself) before Rails pleasantly surprised me. (Maybe PHP would have done this too, but I can''t remember?) Cheers for your help, ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/