Login   Register  
PHP Classes
elePHPant
Icontem

Bug in getYearWeek function

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      phpDateTime  >  All threads  >  Bug in getYearWeek function  >  (Un) Subscribe thread alerts  
Subject:Bug in getYearWeek function
Summary:yearweek of 2012-12-31 is 201201 instead of 201301
Messages:1
Author:Emanuel Indermühle
Date:2013-01-23 00:03:39
 

  1. Bug in getYearWeek function   Reply   Report abuse  
Picture of Emanuel Indermühle
Emanuel Indermühle
2013-01-23 00:03:39
Proposed fix:

function getYearWeek( $date = NULL )
{
if ( NULL === $date )
{
$week = $this->getWeek();
if($week == 1){
$d = new Date($this->getEndOfWeek());
$year = $d->getYear();
}else if($week == 52){
$d = new Date($this->getStartOfWeek());
$year = $d->getYear();
}else{
$year = $this->getYear();
}
return sprintf('%04d%02d', $year, $week);
}

$date = new Date( $date );
return $date->getYearWeek( NULL );
}