On Tue, Jan 11, 2011 at 3:49 AM, Robert Klemme <shortcutter / googlemail.com> wrote: > On Tue, Jan 11, 2011 at 1:45 AM, keldog <kellyrmoran / gmail.com> wrote: >> Hello all... >> >> Wondering if someone can help me out with a date issue. >> >> My environment: >> ruby: 1.9.2p0 >> rails: 3.0.3 >> mac os x >> >> My issue: >> >> From what I've been reading, the date format has been changed in >> 1.9.2. ¨Βο¬ σαφιξη δατειξ τθΆνν―δδ―ωωωζοςνατ θαβεεξ αξ ισσυ>> since 1.9.2 is saving as "dd/mm/yyyy" > > What exactly do you mean by "saving"? ¨ΒοτΆνν―δδ―ωωωαξ> "dd/mm/yyyy" are just textual representations of a Date. ¨Βωοχαξτ > to be sure what conversion is used you can use Date#strftime: I'm pretty sure he's talking about how Date.parse interprets a string of the form "1/2/2011" This form is ambiguous of course, in the US it's normal meaning would be January 1, 2011, where in most of the civilized world it would be February 1, 2011 Date.parse in ruby 1.8.6 tries to use heuristics to decide how to resolve the ambiguity. Ruby 1.9 (and IIRC 1.8.7 as well) did away with this and simply interprets such an input string as February 1. > > 09:44:35 ~$ irb19 -r date > Ruby version 1.9.2 > irb(main):001:0> d = Date.today > => #<Date: 2011-01-11 (4911145/2,0,2299161)> > irb(main):002:0> d.to_s > => "2011-01-11" > irb(main):003:0> d.strftime '%m/%d/%Y' > => "01/11/2011" > irb(main):004:0> d.strftime '%d/%m/%Y' > => "11/01/2011" > irb(main):005:0> > > If you save via Marshal there should be no issues. ¨Βοταμσο τθατ > there are some built in formats: > > irb(main):012:0> d.rfc3339 > => "2011-01-11" > irb(main):013:0> d.rfc2822 > => "Tue, 11 Jan 2011 00:00:00 +0000" > irb(main):014:0> d.rfc822 > => "Tue, 11 Jan 2011 00:00:00 +0000" True but probably mostly irrelevant if I'm interpreting the OPs questions correctly. >> I have a jQuery plugin that uses the date picker and displays in the >> format of "mm/dd/yyyy" ¨Βοχεφεςσονετινετθδατε σαφεαξοτθε>> times it doesn't because of ruby expecting the changed format (mm/dd/ >> yyyy). ¨Βος εψανπμεΊ >> >> 3/1/2011 saves as 1/3/2011 >> 3/13/2011 doesn't save (returns "") > > I would expect the date picker to return a Date and not a String. > What am I missing? The date picker is javascript in a browser, the 'date' needs to be transported via a parameter in a HTTP post, which only allows strings. So the date needs to arrive at the server in the form of a string, which then gets parsed into a ruby date, and this is ultimately done by Date._parse which is the method whose semantics have changed in Ruby 1.8.7/1.9 > >> I have the following code in my model to inspect the date (in my case, >> start_date of a course): >> >> [code] >> ¨Βεζοςείζιμτες Ίζιψίδατεσ before_filter is a controller method, not a model method isn't it? Sorry pure-ruby folks but the OPs question is in the context or Rails. To fix this I think the OP wants to do the conversion from the string in the controller, so that it's already a ruby Date or DateTime by the time AR sees it. Exactly how to do this depends on the controller itself. Asuming that the model involved is Foo, and we have a standard FoosController and a standard form being posted, something like this: def create if (params[:foo] && date_string = params[:foo][:start_date]) params[:start_date] = Date.strptime(date_string), "%m/%d/%Y") end @foo = Foo.create(params[:foo]) if @foo.save #handle case when foo is valid else #handle validation errors end end HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale