title: Get week number with week starting from sunday
body: <p>I currently have this code where I get the week number alongside the start/end day of that week with add and substract buttons:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Date.prototype.getWeekNumber = function() {
    var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
    var dayNum = d.getUTCDay() || 7;
    d.setUTCDate(d.getUTCDate() + 4 - dayNum);
    var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
    return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
  };
  
  var curr;
  weekReset();
  
  function display() {
    start.textContent = curr;
    end.textContent = endOfWeek(curr);
    week.textContent = ("Week " + curr.getWeekNumber());
  }
  
  function weekReset() {
    curr = startOfWeek(new Date());
    display();
  }
  
  function startOfWeek(date) {
    var start = new Date(date);
    start.setHours(0, 0, 0, 0);
    start.setDate(start.getDate() - start.getDay());
    return start;
  }
  
  function endOfWeek(date) {
    date = startOfWeek(date);
    date.setDate(date.getDate() + 6);
    return date;
  }
  
  function weekPlus(weeks) {
    curr.setDate(curr.getDate() + 7 * weeks);
    display();
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="start"&gt;start&lt;/div&gt;
  &lt;div id="end"&gt;end&lt;/div&gt;
  &lt;div id="week"&gt;week&lt;/div&gt;
  &lt;button onclick="weekReset()"&gt;current&lt;/button&gt;
  &lt;button onclick="weekPlus(1)"&gt;add&lt;/button&gt;
  &lt;button onclick="weekPlus(-1)"&gt;substract&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is that it show's the current week number as <strong>34</strong>;</p>
  
  <p>starting on <em>Sun Aug 27</em></p>
  
  <p>ending on <em>Sat Sep 02</em></p>
  
  <p>... when this should be the week number <strong>35</strong>. </p>
  
  <p>So how can I change this function to count sunday as the first day of the week and saturday as the last day of the week?</p>
  
  <p>Any help is appreciated.</p>