Subject: | Bug in Date::Calc::Week_Number() |
Perl Version 5.6.0
Date::Calc Version 4.3
When using Week_Number() on certain dates that fall at around the first week of a new year Week_Number() returns 53 instead of 1.
#! /usr/bin/perl -w
use English;
use Date::Calc qw(:all);
main();
sub main {
$ver = Date::Calc::Version();
print STDOUT ("Date Calc Version:$ver\n");
#These work
$date = 20011230;
testdate();
$date = 20020106;
testdate();
$date = 20021229;
testdate();
$date = 20030105;
testdate();
# Any of these produce the following error.
# Date::Calc::Monday_of_Week(): week out of range at imstat3.pl line ??.
# This is caused by the value returned by week number being 53 for the following dates.
$date = 20011231;
testdate();
$date = 20020101;
testdate();
$date = 20020102;
testdate();
$date = 20020103;
testdate();
$date = 20020104;
testdate();
$date = 20020105;
testdate();
$date = 20021230;
testdate();
$date = 20021231;
testdate();
$date = 20030101;
testdate();
$date = 20030102;
testdate();
$date = 20030103;
testdate();
$date = 20030104;
testdate();
}
sub testdate {
$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
print STDOUT ("$year$month$day\t");
$week = Week_Number($year, $month, $day);
print STDOUT ("$week\t");
# if ($week gt 52) {
# $week = 52;
# }
($year, $month, $day) = Monday_of_Week($week, $year);
print STDOUT ("$year$month$day\n");
}