Sharkie Landshark
2010-Jul-10 16:16 UTC
Rails 3 convert time of created_at before saving to MySQL
How can I prevent this? This happens even if I do not set config.time_zone Basically Rails 3 subtract 7 hours from the current time before saving it to MySQL. I never had this issue in Rails 2.3.5. How would I disable this functionality? Sharkie -- 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.
Sharkie Landshark
2010-Jul-10 16:18 UTC
Re: Rails 3 convert time of created_at before saving to MySQL
I understand a little better now. I am in Bangkok time. Rails converts time into UTC before saving it to MySQL. I do not wish for this behavior. I would rather have created_at stored as Bangkok time as was always the case in Rails 2.3.5. I never wish for this UTC time. -- 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.
Sharkie Landshark
2010-Jul-10 16:47 UTC
Re: Rails 3 convert time of created_at before saving to MySQL
Further investigation, MySQL is running in ICT (Bangkok Time) mysql> select distinct @@system_time_zone from user; +--------------------+ | @@system_time_zone | +--------------------+ | ICT | +--------------------+ 1 row in set (0.00 sec) Sharkie -- 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.
Jeffrey L. Taylor
2010-Jul-10 17:38 UTC
Re: Rails 3 convert time of created_at before saving to MySQL
Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> How can I prevent this? This happens even if I do not set > config.time_zone >config.time_zone = ''Bangkok'' or the appropriate value among the output of: rake time:zones:local HTH, Jeffrey -- 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.
Sharkie Landshark
2010-Jul-10 19:58 UTC
Re: Rails 3 convert time of created_at before saving to MySQL
I tried this, and it does not work and seems to have no effects. What happen now is that created_at is stored in MySQL in UTC time, but when retrieved and displayed in Rails it shows in Bangkok time. It is really no problem with all new data. However, with legacy data in MySQL which have been stored in Bangkok time for the past 3 years, Rails now displays them incorrectly. Jeffrey L. Taylor wrote:> Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: >> How can I prevent this? This happens even if I do not set >> config.time_zone >> > > config.time_zone = ''Bangkok'' > > or the appropriate value among the output of: > > rake time:zones:local > > HTH, > Jeffrey-- 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.
Jeffrey L. Taylor
2010-Jul-10 20:57 UTC
Re: Re: Rails 3 convert time of created_at before saving to MySQL
Did you restart your server? Did you properly migrate config/environment.rb to config/application.rb. I.e., change Rails::Initializer.run do |config| config.time_zone = ''Bangkok'' end to: # config/application.rb module YourApplicationName class Application < Rails::Application config.time_zone = ''Bangkok'' end end It sounds you haven''t completed the migration completely. Jeffrey Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> I tried this, and it does not work and seems to have no effects. > > What happen now is that created_at is stored in MySQL in UTC time, but > when retrieved and displayed in Rails it shows in Bangkok time. It is > really no problem with all new data. > > However, with legacy data in MySQL which have been stored in Bangkok > time for the past 3 years, Rails now displays them incorrectly. > > Jeffrey L. Taylor wrote: > > Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: > >> How can I prevent this? This happens even if I do not set > >> config.time_zone > >> > > > > config.time_zone = ''Bangkok'' > > > > or the appropriate value among the output of: > > > > rake time:zones:local > > > > HTH, > > Jeffrey > > -- > 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. >-- 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.
Sharkie Landshark
2010-Jul-11 08:00 UTC
Re: Re: Rails 3 convert time of created_at before saving to MySQL
I did properly migrate to Rails 3. I no longer have Rails::Initializer.run do |config| Inside class Application < Rails::Application is the only place I have config.time_zone = ''Bangkok'' I restarted a few times as well. Sharkie Jeffrey L. Taylor wrote:> Did you restart your server? Did you properly migrate > config/environment.rb > to config/application.rb. I.e., change > > Rails::Initializer.run do |config| > config.time_zone = ''Bangkok'' > end > > to: > > # config/application.rb > module YourApplicationName > class Application < Rails::Application > config.time_zone = ''Bangkok'' > end > end > > It sounds you haven''t completed the migration completely. > > Jeffrey > > > Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:-- 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.
Pacome Champignac
2010-Oct-01 09:28 UTC
Re: Re: Rails 3 convert time of created_at before saving to MySQL
I just had the same problem and solved it by either : - modify the datatype of my DB attribute from datetime to date (if tou want to store date) OR - convert your data from date to datetime, by using to_datetime (if you want to store datetime) Hope it helps Tomberry Sharkie Landshark wrote:> I did properly migrate to Rails 3. I no longer have > Rails::Initializer.run do |config| > > Inside class Application < Rails::Application is the only place I have > config.time_zone = ''Bangkok'' > > I restarted a few times as well. > > Sharkie > > > Jeffrey L. Taylor wrote: >> Did you restart your server? Did you properly migrate >> config/environment.rb >> to config/application.rb. I.e., change >> >> Rails::Initializer.run do |config| >> config.time_zone = ''Bangkok'' >> end >> >> to: >> >> # config/application.rb >> module YourApplicationName >> class Application < Rails::Application >> config.time_zone = ''Bangkok'' >> end >> end >> >> It sounds you haven''t completed the migration completely. >> >> Jeffrey >> >> >> Quoting Sharkie Landshark <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:-- 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.