Permalink
Browse files

Improved processing dates. [#42 state:resolved]

  • Loading branch information...
paneq committed Apr 16, 2009
1 parent 5f7a627 commit b1450983648a69e0d707aa23c2dac0b950c9edce
Showing with 20 additions and 3 deletions.
  1. +20 −3 app/controllers/application_controller.rb
@@ -31,9 +31,7 @@ def extract_form_errors_id
def get_period(period, return_range = false)
symbol = params[period + "_period"].to_sym
range = if symbol == :SELECTED
start = params[period+'_start']
endt = params[period+'_end']
Range.new(Date.new(start[:year].to_i, start[:month].to_i, start[:day].to_i), Date.new(endt[:year].to_i, endt[:month].to_i, endt[:day].to_i) )
Range.new(from_hash(params[period+'_start']), from_hash(params[period+'_end']))
else
Date.calculate(symbol)
end
@@ -50,4 +48,23 @@ def get_period_range(period)
get_period(period, true)
end


private


# FIXME: To model && write tests
def from_hash(hash)
date = Date.today
begin
date = Date.new(hash[:year].to_i, hash[:month].to_i, hash[:day].to_i)
rescue
begin
date = Date.new(hash[:year].to_i, hash[:month].to_i, 1)
date = date.end_of_month
rescue
end
end
date
end

end

0 comments on commit b145098

Please sign in to comment.