/*
* Created by Magnus 2009-12-27
* Test code for wrong week number bug in Drupal calendar module and/or Drupal core date_week()-function
* Insert this code in calendar.inc on row 86 to test. Other place may work as well, but thats where I did my debugging
*/
$tmp_date_year = 2000;
$tmp_date_month = 1;
$tmp_date_day = 1;
$php_errors = 0;
$drupal_errors = 0;
// Cycles through a couple of years
for ($tmp_date_year = 2000; $tmp_date_year < 2080; $tmp_date_year++ ) {
// Creates the week nr from jan 4ht, it should be 1 or 01
$tmp_date_month = 1;
$tmp_date_day = 4;
$test_date = $tmp_date_year."-".$tmp_date_month."-".$tmp_date_day;
$drupal_week = date_week($tmp_date_year."-".$tmp_date_month."-".$tmp_date_day);
$php_date = mktime(0,0,0,$tmp_date_month,$tmp_date_day,$tmp_date_year);
$php_week = date('W',$php_date);
// Checks if week is 1 or 01 as it should, when not increase errors
if ($php_week != "01") {
$php_errors++;
}
if ( $drupal_week != 1) {
$drupal_errors++;
}
// Prints the week
echo "Drupalweek of ".$tmp_date_year."-".$tmp_date_month."-".$tmp_date_day.": ".$drupal_week."
";
echo "PHPweek of ".$tmp_date_year."-".$tmp_date_month."-".$tmp_date_day.": ".$php_week."
";
// Creates the week nr. from dec 28th and compares to week of dec 31
// dec 28th should always be in the last week the year
$tmp_date_month = 12;
$tmp_date_day = 28;
$test_date = $tmp_date_year."-".$tmp_date_month."-".$tmp_date_day;
$drupal_week = date_week($test_date);
$php_date = mktime(0,0,0,$tmp_date_month,$tmp_date_day,$tmp_date_year);
$php_week = date('W',$php_date);
$last_date = $tmp_date_year."-".$tmp_date_month."-31";
$last_drupal_week = date_week($last_date);
$php_date = mktime(0,0,0,12,31,$tmp_date_year);
$last_php_week = date('W',$php_date);
// Checks if dec 31 is not in same week as dec 28 and increases nr. errors
if ($last_php_week > $php_week) {
$php_errors++;
}
if ( $last_drupal_week > $drupal_week) {
$drupal_errors++;
}
echo "Drupalweek of ".$tmp_date_year."-12-28: ".$drupal_week." Drupalweek of ".$tmp_date_year."-12-31: ".$last_drupal_week."
";
echo "PHPweek of ".$tmp_date_year."-12-28: ".$php_week." Drupalweek of ".$tmp_date_year."-12-31: ".$last_php_week."
";
}
echo "Drupal: ".$drupal_errors.". PHP:".$php_errors."
";