in reply to Calculating the "nearest" week
Try this:
use strict; use warnings; use Time::Local; my $sec_per_day = 60*60*24; my $now = time; my @now = localtime( $now ); my $today_noon = timelocal( 0, 0, 12, @now[ 3..5 ] ); my $delta = ( $now[ 6 ] - 1 ) % 7; my $monday_noon = $today_noon - $delta*$sec_per_day; my $t = $monday_noon; for ( 1 .. 5 ) { my @t = localtime $t; print +( scalar localtime timelocal( 0, 0, 0, @t[ 3..5 ] ) ), $/; $t += $sec_per_day; } __END__ Mon Apr 18 12:00:00 2005 Tue Apr 19 12:00:00 2005 Wed Apr 20 12:00:00 2005 Thu Apr 21 12:00:00 2005 Fri Apr 22 12:00:00 2005
Update: Fixed the algorithm, after getting clarification on the specs from hacker via CB.
the lowliest monk
|
|---|