From: Robert Klemme Date: 2007-03-20T21:30:04+09:00 Subject: Re: Sorting Dates and Times in an array On 19.03.2007 20:57, Paul wrote: > On Mar 19, 1:21 pm, Robert Klemme wrote: >> I think this does not meet the OP's requirements (because of descending >> date). >> >> epoch = Date.new(0) >> @date_array.sort_by {|dt,tm| [epoch - Date.parse(dt), Time.parse(tm)]} >> >> Substraction with epoch will make date components negative and thus lead >> to descending ordering. >> > > Hello Robert, I tried this but I get the following errors: > > irb(main):003:0> epoch = Date.new(0) > ArgumentError: wrong number of arguments (1 for 0) > from (irb):3:in `initialize' > from (irb):3 > > irb(main):005:0> @date_array.sort_by {|dt,tm| [epoch - Date.parse(dt), > Time.parse(tm)]} > NoMethodError: undefined method `parse' for Date:Class > from (irb):5 > from (irb):5:in `sort_by' > from (irb):5 > > Am I missing a 'require' or something to make your lines work? Maybe it's the version? 13:25:57 [~]: irb irb(main):001:0> Date.new 0 NameError: uninitialized constant Date from (irb):1 from :0 irb(main):002:0> require 'date' => true irb(main):003:0> Date.new 0 => # irb(main):004:0> RUBY_VERSION => "1.8.5" irb(main):005:0> Kind regards robert