#!/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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Next business day.
by TStanley (Canon) on Sep 11, 2002 at 16:43 UTC | |
|
Re: Next business day.
by RMGir (Prior) on Sep 11, 2002 at 17:11 UTC |