in reply to code to get the date for "next Thursday"
It might not be any faster, but you can also do it as follows:
use POSIX qw( strftime ); use Time::Local qw( timegm_nocheck ); my ($day, $mon, $year, $wday) = (localtime())[3..6]; # Defaults to now. $year += 1900; $day += (7 - $wday + 4) % 7; $next_th = timegm_nocheck(0,0,0,$day,$mon,$year); print(strftime('%Y-%m-%d', gmtime($next_th)), "\n");
Only core modules are used.
Update: Now using GMT functions for the date to avoid problems from daylight savings time. (This should speed things up a bit too!) The date is still in localtime since we used localtime to fetch the current date.
Update: I had two names for the same variable ($day and $mday). Fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: code to get the date for "next Thursday"
by duckyd (Hermit) on Mar 20, 2006 at 21:15 UTC | |
by bfdi533 (Friar) on Mar 20, 2006 at 22:28 UTC |