I''m doing something like this to highlight an element representing "today" <% classtype = ( Date.today == date ? "day_today" : "day_thisweek" ) %> "date" is of type Date. Works great. EXCEPT if i run it after 9:00 at night. My server is in New Jersey, but because I''m out here in california the date switches over about three hours too early. Now it doesn''t seem as though this should be a big deal. I can get the timezone of the client using javascript and report it back to the server pretty easily. The only problem is that I can''t figure out how to set the timezone offset for a Ruby Date. Date has an "of" field for the timezone offset, but it''s protected (and i don''t understand the logic behind why... dates need timezones just as much as times do). The timezone offset is public in DateTime, which seems like it could potentially help, but then I can''t figure out how to convert a DateTime to a Date while preserving the timezone offset. Am I missing something obvious about how this works in Ruby? Alternately does Rails have an automatic way to handle browser timezones for me that I''m missing? Thanks Mike _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Just thought I''d check in and see if anyone had any suggestions to the below problem about setting the timezone for a Date object. Thanks Mike On 10/19/05, Michael Burton <mb-list-2MT9zwG8tcBAfugRpC6u6w@public.gmane.org> wrote:> > I''m doing something like this to highlight an element representing "today" > > <% classtype = ( Date.today == date ? "day_today" : "day_thisweek" ) %> > > "date" is of type Date. Works great. EXCEPT if i run it after 9:00 at > night. My server is in New Jersey, but because I''m out here in california > the date switches over about three hours too early. > > Now it doesn''t seem as though this should be a big deal. I can get the > timezone of the client using javascript and report it back to the server > pretty easily. > > The only problem is that I can''t figure out how to set the timezone offset > for a Ruby Date. Date has an "of" field for the timezone offset, but it''s > protected (and i don''t understand the logic behind why... dates need > timezones just as much as times do). The timezone offset is public in > DateTime, which seems like it could potentially help, but then I can''t > figure out how to convert a DateTime to a Date while preserving the > timezone offset. > > Am I missing something obvious about how this works in Ruby? Alternately > does Rails have an automatic way to handle browser timezones for me that I''m > missing? > > Thanks > Mike >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hm. There are some notes on this on a blog entry here: http://www.economysizegeek.com/?p=701 You may want to store all the dates in GMT... Yours, Tom On Tue, 2005-10-25 at 15:12 -0700, Michael Burton wrote:> Just thought I''d check in and see if anyone had any suggestions to the > below problem about setting the timezone for a Date object. > > Thanks > Mike > > > > On 10/19/05, Michael Burton <mb-list-2MT9zwG8tcBAfugRpC6u6w@public.gmane.org> wrote: > I''m doing something like this to highlight an element > representing "today" > > <% classtype = ( Date.today == date ? "day_today" : > "day_thisweek" ) %> > > "date" is of type Date. Works great. EXCEPT if i run it > after 9:00 at night. My server is in New Jersey, but because > I''m out here in california the date switches over about three > hours too early. > > Now it doesn''t seem as though this should be a big deal. I > can get the timezone of the client using javascript and report > it back to the server pretty easily. > > The only problem is that I can''t figure out how to set the > timezone offset for a Ruby Date. Date has an "of" field for > the timezone offset, but it''s protected (and i don''t > understand the logic behind why... dates need timezones just > as much as times do). The timezone offset is public in > DateTime, which seems like it could potentially help, but then > I can''t figure out how to convert a DateTime to a Date while > preserving the timezone offset. > > Am I missing something obvious about how this works in Ruby? > Alternately does Rails have an automatic way to handle browser > timezones for me that I''m missing? > > Thanks > Mike > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails