Marek Osvald
2011-Jul-26 11:52 UTC
MySQL returns time with UTC time zone instead of local one
Hey, I''m trying to write a simple application with Ruby on Rails that works in my timezone (Prague, UTC + 1). I''ve set my application.rb like this: #application.rb config.time_zone = ''Prague'' and it seems to be working, for example:> Time.now=> 2011-07-26 13:46:06 +0200 #(+0200 because of the daylight saving time) when i try to save the record to the database it workes and stores itself in the UTC timezone (as it''s supposed to), however, when I try to load the model from the database, for example:> OpeningHour.first.opening_hour=> 2000-01-01 05:00:00 UTC it returns the value in the UTC time zone. Is it supposed to do that? Every time zone tutorial I''ve stumbled upon so far shows that Rails should convert the value to the local timezone. I''m using mysql2 gem and MySQL 5.5 (x64) on Windows 7. Thanks for any help. Marek -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jul-26 12:34 UTC
Re: MySQL returns time with UTC time zone instead of local one
On Jul 26, 12:52 pm, Marek Osvald <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hey, > > I''m trying to write a simple application with Ruby on Rails that works > in my timezone (Prague, UTC + 1). I''ve set my application.rb like this: > > #application.rb > config.time_zone = ''Prague'' > > and it seems to be working, for example: > > > Time.now > > => 2011-07-26 13:46:06 +0200 #(+0200 because of the daylight saving > time) > > when i try to save the record to the database it workes and stores > itself in the UTC timezone (as it''s supposed to), however, when I try to > load the model from the database, for example: > > > OpeningHour.first.opening_hour > > => 2000-01-01 05:00:00 UTC > > it returns the value in the UTC time zone. Is it supposed to do that? > Every time zone tutorial I''ve stumbled upon so far shows that Rails > should convert the value to the local timezone. >That looks like a time column rather than a datetime column. I believe time columns are supposed to just represent a time of day, without reference to timezone. Apart from anything else, since there is no associated date you can''t (in general) convert it from UTC to a local timezone. Fred> I''m using mysql2 gem and MySQL 5.5 (x64) on Windows 7. > > Thanks for any help. > > Marek > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marek Osvald
2011-Jul-26 14:18 UTC
Re: MySQL returns time with UTC time zone instead of local one
You were right. Thanks a lot, pal. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.