Skip to content

Commit

Permalink
Improved processing dates. [#42 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
paneq committed Apr 16, 2009
1 parent 5f7a627 commit b145098
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions app/controllers/application_controller.rb
Expand Up @@ -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
Expand All @@ -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.