[retoh@secundus date]$ cat date.pl
#!/usr/bin/perl -w
$| = 1;
use strict;
use Date::Manip;
# -- GLOBAL
# my $tz = Date_TimeZone();
my $date_res;
my @MM_NAMES = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC);
# -- MAIN
$date_res = &getNext(date => '2005-04-20', add => '+ 48hours');
print '<-- Weekday ', $date_res->{'weekday_num'}, "\n";
print '<-- ', $date_res->{'date_eu'}, "\n";
print "\n";
$date_res = &getNext(date => '2005-04-30');
print '<-- Weekday ', $date_res->{'weekday_num'}, "\n";
print '<-- ', $date_res->{'date_eu'}, "\n";
######################################################
sub getNext(%) {
######################################################
my %args = @_;
$args{'add'} ||= '+ 24hours';
my %result = ();
my ($i_yyyy, $i_mm, $i_dd) = split /\-/, $args{'date'};
print "--> Input: $i_dd $MM_NAMES[$i_mm - 1] $i_yyyy $args{'add'}\n";
$result{'weekday_num'} = Date_DayOfWeek($i_mm, $i_dd, $i_yyyy);
my $err = '';
my $date = DateCalc("$i_dd $MM_NAMES[$i_mm - 1] $i_yyyy",
$args{'add'}, \$err) || '';
$err ||= 0;
my $yyyy = substr($date, 0, 4);
my $dd = substr($date, 4, 2);
my $mm = substr($date, 6, 2);
$result{'date_eu'} = "$mm\.$dd\.$yyyy";
\%result;
}
Output
$ ./date.pl
--> Input: 20 APR 2005 + 48hours
<-- Weekday 3
<-- 22.04.2005
--> Input: 30 APR 2005 + 24hours
<-- Weekday 6
<-- 01.05.2005