Wagner, David --- Senior Programmer Analyst --- WGO wrote: > 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.
I got to playing with the code I sent to Kevin and found out that if you don't do some type of aligning of date, that by starting with 21 Mar 2003 then by Mar 2001, the month info would have gone to such as to display Mar 01 Mar 01 instead of Mar 01 Feb 01. Here is the modified code. Wags ;) =============================================================================================== #!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); printf "Current Date for processing: %02d/%02d/%02d\n", $TimeInfo->[9], $TimeInfo->[4], $TimeInfo->[3]; if ( $TimeInfo->[3] != 15 ) { $diff = $TimeInfo->[3] - 15; get_time($TimeInfo); } my $MyWorkInTime = $TimeInfo->[10]; my $MyThirtyDays = 30 * 86_400; printf "Start Date for processing: %02d/%02d/%02d\n", $TimeInfo->[9], $TimeInfo->[4], $TimeInfo->[3]; for(my $MyId=12;$MyId>0;$MyId--) { push( @MyMonths, ($MyMonthDesc[$TimeInfo->[4]] . ' ' . sprintf "%02d", $TimeInfo->[9])); $MyWorkInTime -= $MyThirtyDays; get_time( $TimeInfo, $MyWorkInTime ); if ( $TimeInfo->[3] != 15 ) { # # I am changing the epoch seconds to be at the 15th of them month. This should be a # plus or minus of 2 or at max 3. I don't need to re-calculate the date array, # just modify the epoch seconds. # $MyWorkInTime += ( 15 - $TimeInfo->[3] ) * 86_400; } } foreach ( @MyMonths ){ printf "%-s\n", $_; } #printf "%-s\n", 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 ## # ********************************************************** 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]