Siegfried Heintze wrote:
> Given the current date, I want to compute the date of the Sunday
> before. There are a lot of date packages on CPAN. Can someone
> recommend one that would be well suited for this calculation?
> Siegfried
How do you want to handle Sunday? Is that the previous Sunday or the
day you run? I would just roll my own using localtime. Since the 6th item is
the day of the week, you can use that calculate the prior Sunday. I have my
own little routine which I use in my scripts which takes an array reference and
a secondary time variable.
Here is a start( not tested):
#!perl
use strict;
use warnings;
my @TI = ();
my $TimeInfo = [EMAIL PROTECTED];
get_time( $TimeInfo );
my $MyDiff = 7;
$MyDiff = $TimeInfo->[6] if ( $TimeInfo->[6] );
my $MyPointInTime = $TimeInfo->[10] - MyDiff * 86_400;
get_time( $TimeInfo, $MyPointInfo );
#
# Now you have the prior Sunday
# If you want to use current sunday as the Sunday then change the 7 to
0 and you are set.
#
# Subs here
#
sub get_time {
my ( $TimeInfo, $MyUseTime ) = @_;
# 0 1 2 3 4 5 6 7 8
# ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time -
$diff);
# 9 => YearModulo
# 10 => Time used in calculations
#
my $MyPointInTime = time;
$MyPointInTime = $MyUseTime if ( defined $MyUseTime );
@{$TimeInfo} = localtime( $MyPointInTime );
$TimeInfo->[4]++;
$TimeInfo->[9] = $TimeInfo->[5] % 100; # Year Modulo, last two digits of
year
$TimeInfo->[10] = $MyPointInTime;
} # end of get_time
*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>