title: Getting data from postgres weekly (according to date)
body: <pre><code>user  timespent(in sec)  date(in timestamp)
  u1       10                t1(2015-08-15)
  u1       20                t2(2015-08-19)
  u1       15                t3(2015-08-28)
  u1       16                t4(2015-09-06)
  </code></pre>
  
  <p>Above is the format of my table, which represents timespent by user on a course and it is ordered by timestamp. I want to get sum of timespent by a particular user, say u1 weekly in the format :</p>
  
  <pre><code>start_date    end_date       sum
  2015-08-15   2015-08-21      30
  2015-08-22   2015-08-28      15
  2015-08-29   2015-09-04      0
  2015-09-05   2015-09-11      16
  </code></pre>