Skip to content

Instantly share code, notes, and snippets.

@jvoorhis
Created August 5, 2009 18:20
Show Gist options
  • Save jvoorhis/162870 to your computer and use it in GitHub Desktop.
Save jvoorhis/162870 to your computer and use it in GitHub Desktop.
def times_for_period(date)
days = work_days_for_period(date)
regular_hours_by_week = Hash.new(0)
out = { :regular_hours => 0, :other_hours => Hash.new(0) }
days.inject(out) { |results, day|
times = day.times
{ :regular_hours => results[:regular_hours] + times[:regular_hours]
:other_hours => results[:other_hours].merge(times[:other_hours]) { |_,a,b| a+b }}
}.merge(:weekly_hours => regular_hours_by_week.values_at(*regular_hours_by_week.keys.sort))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment