title: group hash of dates by week/month/year
body: <p>Given this hash in ruby:</p>
  
  <pre><code>h={
  2010-03-01=&gt;2
  2010-03-02=&gt;4
  2010=03-03=&gt;1
  ..
  ..
  n days with working hours
  }
  </code></pre>
  
  <p>where hash key is a date and hash value is an integer, how do I transform this hash into a new hash where keys are weeks/months/years (with aggregation)?</p>
  
  <p>Let me show an example with weeks, the end result should look like:</p>
  
  <pre><code>h_weeks={7=&gt;36, 8=&gt;42, 9=&gt;34 ..,..,n}
  </code></pre>
  
  <p>with months:</p>
  
  <pre><code>h_months={1=&gt;170, 2=&gt;180, 3=&gt;146}
  </code></pre>
  
  <p>with years:</p>
  
  <pre><code>h_years={2009=&gt;950, 2010=&gt;446}
  </code></pre>
  
  <p>where key is a week number(month/year), and value is an aggregate of working hours within this week/month/year.</p>
  
  <p>I'm writing a small working hours tracking application and would like to group this data.</p>
  
  <p>Thanks.</p>