title: Get the most recently occurring Sunday
body: <p>I need to display the current week in a calendar view, starting from Sunday.</p>
  
  <p>What's the safest way to determine "last sunday"  in Javascript?</p>
  
  <p>I was calculating it using the following code:</p>
  
  <pre><code>Date.prototype.addDays = function(n) {
        return new Date(this.getTime() + (24*60*60*1000)*n);
  }
  
  var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  var lastSunday = today.addDays(0-today.getDay());
  </code></pre>
  
  <p>This code makes the assumption that every day consists of twenty four hours. This is correct, EXCEPT if it's a daylight savings crossover day, in which case the day could be twenty-three or twenty-five hours.</p>
  
  <p>This week, In Sydney, Australia, we set our clocks forward an hour. As a result, my code calculates <code>lastSunday</code> as 23:00 on Saturday.</p>
  
  <p>So what IS the safest and most efficient way to determine last Sunday?</p>