Seeing the Future with Perl
Adjusting time forwards (and backwards) is easy with Perl.
But before we start playing around with the future, let's determine exactly what time it is now to the second (according to the server).
my ($second, $minute, $hour, $month_day, $month, $year, $week_day, $year_day, $is_DST) = localtime;
That snippet retrieves a lot of information about this moment. The same information can be retrieved for any future or past moment.
The $second and $minute variables contain a number 0-59, the $hour variable 0-23.
The $month_day variable contains the calendar day of the month (the number, not the day itself :).
The $month variable contains a number 0-11. January is 0 and December is 11.
The $year variable contains the current 4-digit year minus 1900. Thus, year 2005 would be represented as "105".
The $week_day variable contains a number 0-6. Sunday is 0, Monday is 1, and Saturday is 6.
The $year_day variable contains a count of the number of days elapsed since January 1 of the current year. January 1 is 0, January 2 is 1, January 31 is 30, February 1 is 31, February 2 is 32, and so forth.
The $is_DST variable is either empty or it contains a non-zero number (usually the digit 1). If it contains a non-zero number, it is Daylight Savings Time. If empty, it is not Daylight Savings Time.
Notice that the localtime function retrieves 9 items of information. If you only need only one item, the information can be retrieved independently.
The 9 items the localtime function retrieves can be numbered 0 through 8. Thus, the day of the week number would be number 6.
This retrieves the day of the week number:
my $WeekDay = (localtime)[6];
Now, let's see the future.
A future moment is determined by adding seconds to the current system time.
The current system time is retrieved with the time function.
This snippet adds a years worth of seconds to the current system time, then prints the day of the week for that future.
my $then = time; $then += 60 * 60 * 24 * 365; my $ThenWeekDay = (localtime($then))[6]; print $ThenWeekDay;
The value of the $now variable, which contains a system time number of a time in the future, is passed to the localtime function, which then returns the day of the week for that future time.
See how easy it is to see the future with Perl :)
Will Bontrager