Hello, There appears to be a strange bug in Rails 2.1.1 where if I set a datetime field to YYYY-MM-DD 00:00:00 (using TimeZone support) Rails returns nil, instead of YYYY-MM-DD 00:00:00 Here is confirmed output:>> c = Clip.find(53385)=> #<Clip id: 53385, title: "test 2", description: "test2", keywords: "test2", publish_date: "2008-11-03 11:13:00">>> c.publish_date = "2008-11-03 19:00:00"=> "2008-11-03 19:00:00">> c.save=> true>> c = Clip.find(53385)=> #<Clip id: 53385, title: "test 2", description: "test2", keywords: "test2", publish_date: nil>>> c.publish_date=> nil Any reason for this behavior ? Adam --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2008-Nov-03 23:16 UTC
Re: Rails 2.1.1 setting datetime to nil at 00:00:00
> Hello, > There appears to be a strange bug in Rails 2.1.1 where if I set a > datetime > field to YYYY-MM-DD 00:00:00 (using TimeZone support) Rails returns > nil, > instead of YYYY-MM-DD 00:00:00 > > Here is confirmed output: > >>> c = Clip.find(53385) > => #<Clip id: 53385, title: "test 2", description: "test2", keywords: > "test2", publish_date: "2008-11-03 11:13:00"> >>> c.publish_date = "2008-11-03 19:00:00" > => "2008-11-03 19:00:00" >>> c.save > => true >>> c = Clip.find(53385) > => #<Clip id: 53385, title: "test 2", description: "test2", keywords: > "test2", publish_date: nil> >>> c.publish_date > => nilYour example isn''t setting it to 00:00:00, but 19:00:00 ? Also, what does the database say? I''d want to see it confirmed there as well. And lastly, are there any before/after filters on this model? Any triggers in the database that might affect it? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I used 19:00 b/c of Time zones (EST is GMT-5). I have a before_filter that sets the time zone to either the users time zone, or EST by default. Database is storing it as 00:00:00 b/c we store as UTC before_filter: Time.zone = current_user.timezone ? current_user.timezone : $DEFAULT_TIME_ZONE where DEFAULT is EST mysql> select id,publish_date from clips where id=53385 ; +-------+---------------------+ | id | publish_date | +-------+---------------------+ | 53385 | 2008-11-04 00:00:00 | +-------+---------------------+ Its a datetime field in DB | publish_date | datetime Adam On Mon, Nov 3, 2008 at 5:03 PM, AD <straightflush-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > There appears to be a strange bug in Rails 2.1.1 where if I set a datetime > field to YYYY-MM-DD 00:00:00 (using TimeZone support) Rails returns nil, > instead of YYYY-MM-DD 00:00:00 > > Here is confirmed output: > > >> c = Clip.find(53385) > => #<Clip id: 53385, title: "test 2", description: "test2", keywords: > "test2", publish_date: "2008-11-03 11:13:00"> > >> c.publish_date = "2008-11-03 19:00:00" > => "2008-11-03 19:00:00" > >> c.save > => true > >> c = Clip.find(53385) > => #<Clip id: 53385, title: "test 2", description: "test2", keywords: > "test2", publish_date: nil> > >> c.publish_date > => nil > > Any reason for this behavior ? > > Adam >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
confirmed to be an issue with validates_date_time http://www.semergence.com/2006/12/20/validates_date_time-not-ready-for-prime-time/ On Mon, Nov 3, 2008 at 7:07 PM, AD <straightflush-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I used 19:00 b/c of Time zones (EST is GMT-5). I have a before_filter that > sets the time zone to either the users time zone, or EST by default. > Database is storing it as 00:00:00 b/c we store as UTC > before_filter: Time.zone = current_user.timezone ? > current_user.timezone : $DEFAULT_TIME_ZONE where DEFAULT is EST > > mysql> select id,publish_date from clips where id=53385 ; > +-------+---------------------+ > | id | publish_date | > +-------+---------------------+ > | 53385 | 2008-11-04 00:00:00 | > +-------+---------------------+ > > Its a datetime field in DB > | publish_date | datetime > > Adam > > On Mon, Nov 3, 2008 at 5:03 PM, AD <straightflush-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello, >> There appears to be a strange bug in Rails 2.1.1 where if I set a >> datetime field to YYYY-MM-DD 00:00:00 (using TimeZone support) Rails returns >> nil, instead of YYYY-MM-DD 00:00:00 >> >> Here is confirmed output: >> >> >> c = Clip.find(53385) >> => #<Clip id: 53385, title: "test 2", description: "test2", keywords: >> "test2", publish_date: "2008-11-03 11:13:00"> >> >> c.publish_date = "2008-11-03 19:00:00" >> => "2008-11-03 19:00:00" >> >> c.save >> => true >> >> c = Clip.find(53385) >> => #<Clip id: 53385, title: "test 2", description: "test2", keywords: >> "test2", publish_date: nil> >> >> c.publish_date >> => nil >> >> Any reason for this behavior ? >> >> Adam >> > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Whenever I need to store and manipulate a date independent of time, I prefer using the SQL Date type and corresponding ActiveSupport Date type. It''s a lot cleaner for parsing and validating. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---