title: php date/week problem
body: <p>I'm kind of at a loss here. It seems as though somehow my code is missing a whole week at the end of 2009 and I've tried a couple different things.</p>
  
  <p>My base function to get the start and end date for a week is below. Given a Year, Week and Day of the Week it gives you a date.</p>
  
  <pre><code>function datefromweeknr($aYear, $aWeek, $aDay)
      {
          $Days=array('xx','ma','di','wo','do','vr','za','zo');
          //xx = Current Sun, ma = Mon ..... zo = Sun of the next Week
          $DayOfWeek=array_search($aDay,$Days); //get day of week (1=Monday)
          $DayOfWeekRef = date("w", mktime (0,0,0,1,4,$aYear)); //get day of week of January 4 (always week 1)
          if ($DayOfWeekRef==0){
              $DayOfWeekRef=7;
          }
          $ResultDate=mktime(0,0,0,1,4,$aYear)+((($aWeek-1)*7+($DayOfWeek-$DayOfWeekRef))*86400);
          return $ResultDate;
      }
  </code></pre>
  
  <p>Seemed to work completely fine until I realized that I was missing the week of December 27th 2009 to January 2nd 2010.</p>
  
  <pre><code>echo '&lt;table border="1"&gt;';
  for($i = 1; $i &lt; 53; $i++){
      if($i &lt; 10){
          $w = '0'.$i.'1';
      }
      else{
          $w = $i.'1';
      }
      echo '&lt;tr&gt;&lt;td&gt;Week#'.$i.' &lt;/td&gt;&lt;td&gt; '.date("Y-m-d",datefromweeknr(2009,$i,"xx")).' &lt;/td&gt;&lt;td&gt; '.date("Y-m-d",datefromweeknr(2009, $i,"za")).'&lt;/td&gt;&lt;td&gt; Week = '.date("W: Y-m-d",strtotime("2009W$w")).'  &lt;/td&gt;&lt;/tr&gt;';
  
  }
  
  echo '&lt;/table&gt;';
  </code></pre>
  
  <p>It seems the 52nd week of the year ends on 2009-12-26 and the 1st week of the new year starts on 2010-01-03. I'm losing a whole week, No Bueno!</p>
  
  <p>Anyone know what I'm doing wrong or can point me to a fool proof way of supplying a week number and a year to get me the start and end date of that week without losing any days in the process?</p>