Eww. I don't think you should use Date::Calc or Date::Manip for this. I think you should use Time::Local.
use Time::Local; sub getFirstNonWeekend { my ($month, $year) = @_; # (7,2001) for July 2001 # noon on the 1st of the month my $first = timelocal(0,0,12, 1, $month-1, $year-1900); my $shift = ((localtime $first)[6] + 1) % 7; if ($shift < 2) { $first += 86400 * (2 - $shift) if $shift < 2; return ($first, 3 - $shift, 1); } return ($first, 1, $shift - 1); }
That will give you the time for (around) noon on the first day of a given month that is NOT a weekend, the day of the month, and a number representing the day of the week (1 = Monday, 5 = Friday). That's probably the hardest part.

What's left is the partitioning of this month and the next. Since you know the day of the month and the day of the week, this shouldn't be too hard. I wouldn't mind showing you the code for it though, if you ask.

japhy -- Perl and Regex Hacker


In reply to Re: Getting Weekly Dates by japhy
in thread Getting Weekly Dates by mothra

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.