Skip to content

Instantly share code, notes, and snippets.

@raggi
Created August 5, 2009 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raggi/162942 to your computer and use it in GitHub Desktop.
Save raggi/162942 to your computer and use it in GitHub Desktop.
def times_for_period(date)
regular_hours_by_week = Hash.new(0)
regular_hours = 0
other_hours = Hash.new(0)
work_days_for_period(date).each do |d|
times = d.times
regular_hours += times[:regular_hours]
regular_hours_by_week[d.date.cweek] += times[:regular_hours]
times[:other_hours].each { |k,v| other_hours[k] += v }
end
weekly_hours = regular_hours_by_week.keys.sort.map do |k|
regular_hours_by_week[k]
end
{
:regular_hours => regular_hours,
:other_hours => other_hours,
:weekly_hours => weekly_hours
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment