Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: big bug in Date::Calc?

by choroba (Abbot)
on Feb 19, 2013 at 11:30 UTC ( #1019525=note: print w/ replies, xml ) Need Help??


in reply to big bug in Date::Calc?

Use strict and warnings. Do not use global variables.

#!/usr/bin/perl use warnings; use strict; use Date::Calc qw ( Monday_of_Week Add_Delta_Days ); sub weekToDays { my $week = shift; my $year = shift; my ($year2, $month, $day) = Monday_of_Week($week, $year); my ($y, $m, $d) = Add_Delta_Days( Monday_of_Week($week, $year), 6) +; # Not $year2 here! return "$day/$month/$year2 to $d/$m/$y"; } print "First week of 2013: ".weekToDays ( 1, 2013) ."\n" ; print "Second week of 2013: ".weekToDays ( 2, 2013) ."\n" ;

Output:

First week of 2013: 31/12/2012 to 6/1/2013 Second week of 2013: 7/1/2013 to 13/1/2013
Update: You can even avoid calling the function again when you already know the result:
my ($y, $m, $d) = Add_Delta_Days($year2, $month, $day, 6);
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: big bug in Date::Calc?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019525]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (18)
As of 2014-08-29 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (282 votes), past polls