#!/bin/perl # This is something I cobbled together one day to keep track of dates. # Given a Saturday's date, I wanted to be able to get next Saturday's date. # (See my first attempt in date1.pl) # # This is improved because I wanted to maintain a human-readable date # value, e.g. 12/07/2001, not the number of seconds, 1007798400. # This makes it easy for a person to maintain the state file and gives # us something we can easily use for a directory name. $mm=12; $dd=7; $yyyy=2001; # A starting point, 12/07/2001. $mm=3; $dd=24; $yyyy=2001; # or 03/24/2001. use Time::Local; # Need this to get timelocal defined. @z2=('00' .. '32'); # A handy array to get zero-padding on my mm/dd; # See Perl book on page 104. print " Starting with $z2[$mm]/$z2[$dd]/$yyyy,\n"; for (1..60) { # Loop through a year to prove this works across # Daylight Savings time, New Year's, and Leap Day transitions. # Note the interesting way of saying, do something 60 times. # Inside this loop, $_ is our loop index, ranging from 1 to 60. # Note that 608400 seconds = 1 week + 1 hour. This handles the fall # Daylight Savings Time transition correctly, and since we don't care # about the time of day, we can get away with this "sloppiness". $number_seconds = timelocal(0,0,0,$dd,$mm-1,$yyyy-1900) + 608400; # A cute way to extract just a slice of what localtime returns. ($dd,$mm,$yyyy)=(localtime($number_seconds))[3..5]; $mm++; $yyyy+=1900; # Adjust for localtime's idiosyncracies. print "one more week makes it $z2[$mm]/$z2[$dd]/$yyyy,\n"; }