This is a short snippet to calculate the next business day. It takes into account a holiday metric of days to skip past, as well. Admittedly, this is probably more complicated than it needs to be, and if anyone would care to golf it, I'd love to see the input on how to make it shorter/faster/more efficient.
#!/usr/local/bin/perl -w # Calculate the next business day taking into account a # holiday metric. use strict; my $next_business_day = _calc_next_date(); print "Next business day: $next_business_day\n"; sub _calc_next_date { use POSIX qw(strftime); # Set up the holiday metric -- skip past these dates. my @_holiday = ('01/01', '01/21', '03/29', '05/27', '07/04', '09/02', '10/28', '10/29', '12/24', '12/25'); my $_today = `date +"%m/%d"`; chomp($_today); my $_today_day = `date +"%a"`; chomp($_today_day); my $_good_date = 0; my $_next_date; my $_amount = 0; # Loop until we get a weekday that isn't in the holiday metric. until ($_good_date) { if ($_today_day eq 'Fri') { $_amount += 259200; } else { $_amount += 86400; } $_next_date = strftime "%m/%d", localtime(time + $_amount); foreach (@_holiday) { if ($_ eq $_next_date) { $_amount = $_amount + 86400; } } $_next_date = strftime "%m/%d", localtime(time + $_amount); my $_next_day = strftime "%a", localtime(time + $_amount); if (($_next_day ne 'Sat') && ($_next_day ne 'Sun')) { $_good_date = 1; foreach (@_holiday) { if ($_ eq $_next_date) { $_good_date = 0; } } } } $_next_date = strftime "%m/%d/%y", localtime(time + $_amount); return $_next_date; }

In reply to Next business day. by sschneid

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.