Yeah, I was going to add a note to that effect, but I seem to have forgotten.
Dealing with that isn't much more complex, you just need to use Time::Local and normalise the times to midday. That way you can be sure that subtracting 86,400 seconds will get you to the previous day. Like this:
use Time::Local;
use POSIX 'strftime';
# get today
my @today = localtime;
# normalise to midday
@today[0 .. 2] = (0, 0, 12);
# get normalised today
my $today = timelocal @today;
# get current day of week
my $dow = (localtime($today))[6];
# get last Sunday (day 0)
my $sunday = $today - (86_400 * $dow);
# get Tuesday (day 2)
my $tuesday = $sunday + (86_400 * 2);
# print Tuesday in a nice format
print strftime "Tuesday is %d %B %Y\n", localtime $tuesday;
--
<http://www.dave.org.uk>
"The first rule of Perl club is you do not talk about
Perl club." -- Chip Salzenberg
|