On Wed, Jul 18, 2001 at 12:32:21PM -0400, [EMAIL PROTECTED] wrote:
> Is there a easy way to have perl generate information to find out what the
> 3rd friday is for each month? I have been looking at some cpan modules
> and none of them seem to do what I need.
Date::Calc has a subroutine, Nth_Weekday_of_Month_Year. It looks to be
exactly what you want.
Were you to do it manually, finding the third friday is a matter of finding
the first friday of the month and adding two weeks.
#!/usr/bin/perl -w
use Time::Local;
use strict;
use constant FRIDAY_WDAY => 5;
use constant SECS_IN_A_DAY => (60 * 60 * 24);
use constant DAYS_IN_A_WEEK => 7;
my $third_friday =
get_first_friday() + (SECS_IN_A_DAY * DAYS_IN_A_WEEK * 2);
print scalar localtime($third_friday), "\n";
sub get_first_friday {
my $month_start = timelocal(0, 0, 0, 1, (localtime)[4,5]);
my @month_start = localtime($month_start);
my $first_friday;
if ($month_start[6] > FRIDAY_WDAY) {
$first_friday =
$month_start +
(SECS_IN_A_DAY * ($month_start[6] - FRIDAY_WDAY))
;
} elsif ($month_start[6] < FRIDAY_WDAY) {
$first_friday =
$month_start +
(SECS_IN_A_DAY * (FRIDAY_WDAY - $month_start[6]))
;
} else {
$first_friday = $month_start;
}
return $first_friday;
}
> I did find something that might do it but it requires compiling c code and
> I thought there might be a easier method.
That's probably the Date::Calc module. Is the manual method I showed above
truly easier on readability and resources than compiling?
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]