Here's a test case for you; it lets you crosscheck your sub against localtime for localtime's range.
Obviously needs a bit of work to be recast as a test case, sorry.#!/usr/bin/perl -w use strict; sub day_of_week { my ($year, $month, $day) = @_; my @offset = (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); $year -= $month < 3; return ($year + int($year/4) - int($year/100) + int($year/400) + $offset[$month-1] + $day) % 7; } my $i=0; for(my $time=1; $time<2**31; $time+=86400) { my ($mday,$mon,$year,$wday)=(localtime($time))[3..6]; $mon++; $year+=1900; my $day=day_of_week($year,$mon,$mday); # progress info... print ((scalar localtime($time))," $day, $wday\n") unless ($i++%10 +00); if($day != $wday) { print "Mismatch between sub ($day) and localtime ($wday) for " +, (scalar localtime($time)),"\n"; } }
Your routine passes on my system :)
--
Mike
In reply to Re: Day of the week
by RMGir
in thread Day of the week
by jmcnamara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |