Skip Menu |

This queue is for tickets about the Date-Calc CPAN distribution.

Report information
The Basics
Id: 2162
Status: resolved
Priority: 0/
Queue: Date-Calc

People
Owner: STBEY [...] cpan.org
Requestors: bill.mcdonald [...] wcom.com
Cc:
AdminCc:

Bug Information
Severity: Unimportant
Broken in: 4.3
Fixed in: 4.3



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"); }
RT-Send-CC: sb [...] engelschall.com
Dear Bill! First of all, your version of Date::Calc (4.3) is awfully old. You probably want to update in order to benefit from new functionality (like date objects with overloaded operators and calendar calculations with holidays). Second, you should have read the documentation first before posting a bug report; this is a documented behaviour. The function returns zero if the week number is the LAST week in the PREVIOUS year and number_of_weeks_in_given_year + 1 (usually 53) when the given date belongs to the FIRST week of the NEXT year. You probably want to use the function ($week,$year) = Week_of_Year($year,$month,$day); instead which also returns the number of the year that week belongs to. Hope this helps. Regards, Steffen