Kevin Old wrote:
> Hello everyone,
> 
> I'm trying to create an array of months that will be a continuous
> "Moving View of Months".  I will have an page served to users that
> has a table of the past 12 months.  For instance, if I were to pull
> up the page today, it would display Apr 02 - Mar 03.  Next month it
> will be May 02 - Apr 03.
> 
> I'm able to create the array, but think there might be a much more
> efficient way to do it.
Kevin,
  Here is a quick shot at it just using std Perl and no other modules.  I do a check 
on days and if greater than 27(ie 28 to 31) then I subtract back to the middle of the 
month and run from there.  I have a simple get_time routine which I use to get 
date/time info for my modules.

Wags ;)

Perl code starts on next line:
#!perl -w

my @MyMonthDesc = qw(dum Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);

my @MyMonths = ();

my @TI = ();
my $TimeInfo = [EMAIL PROTECTED];
$diff = 0;

get_time( $TimeInfo);

if ( $TimeInfo->[3] > 27 ) {
    $diff = $TimeInfo->[3] - 15;
    get_time($TimeInfo);
 }
my $MyWorkInTime = $TimeInfo->[10];
my $MyThirtyDays = 30 * 86_400;

for(my $MyId=12;$MyId>0;$MyId--) {
    push( @MyMonths, ($MyMonthDesc[$TimeInfo->[4]] . ' ' . sprintf "%02d", 
$TimeInfo->[9]));
    $MyWorkInTime -= $MyThirtyDays;
    get_time( $TimeInfo, $MyWorkInTime );
 }
printf "%-s", join( '  ', @MyMonths);

#
##
### Subroutines go here
##
#

sub get_time {
    my ( $TimeInfo, $MyUseTime ) = @_;
    $diff = 86400 * $diff;
#    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 - $diff;
    $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;
    
    $diff = 0;

 }  # end of get_time

#
##
### Subroutines end
##
#
^--------------- Perl Code ends here

Output (todays date: $diff ):
Mar 03  Feb 03  Jan 03  Dec 02  Nov 02  Oct 02  Sep 02  Aug 02  Jul 02  Jun 02  May 02 
 Apr 02

Set $diff to a -15 ( puts us into Apr)

Apr 03  Mar 03  Feb 03  Jan 03  Dec 02  Nov 02  Oct 02  Sep 02  Aug 02  Jul 02  Jun 02 
 May 02

I know you said you wanted to use the other routines, but why go to such hard work, 
when the normal Perl installation will handle the processing for you.

Wags ;)


**********************************************************
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]

Reply via email to