Hi, I think I've found a bug in Date::Calc with add_delta_days function. I get a week number and a year in my function and I want to calculate the date starting and ending that week. To calculate it, I use supplied Monday_of_week (first day), then I add 6 days to it to get the Sunday. Trying this function with:
print weeksToDays ( 1, 2013) ; (1st week of 2013)
it returns:
31/12/2012 to 8/1/2012 (it should be ...to 6/1/2013)
while:
print weeksToDays ( 2, 2013) ; (2nd week of 2013)
it returns:
7/1/2013 to 13/1/2013
which is correct.
use Date::Calc qw ( Monday_of_Week Add_Delta_Days ); sub weekToDays { $week = shift; $year = shift; ($year,$month,$day) = Monday_of_Week($week,$year); ($y, $m, $d) = Add_Delta_Days( Monday_of_Week( $week, $year ), 6); return "$day/$month/$year to $d/$m/$y"; } print "First week of 2013: ".weekToDays ( 1, 2013) ."\n" ; print "Second week of 2013: ".weekToDays ( 2, 2013) ."\n" ;

Update: Thank you to all. One word: I'm a dumb idiot :D


In reply to big bug in Date::Calc? by luca76

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.