Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!sun-barr!apple!netcom!amdcad!brahms!cdr From: cdr@brahms.amd.com (Carl Rigney) Newsgroups: comp.lang.perl Subject: Re: Perl subroutine libraries? Summary: zeller's congruence Keywords: weekday perl subroutine Message-ID: <1990Oct2.172114.6421@amd.com> Date: 2 Oct 90 17:21:14 GMT References: <11802@bsu-cs.bsu.edu> Sender: usenet@amd.com (NNTP Posting) Organization: Advanced Micro Devices; Sunnyvale, CA Lines: 34 Here's a simple subroutine to calculate Day of the Week using Zeller's Congruence, which I've found very useful. A lot of the temporary variables could be omitted by making it harder to read. If Randal wants to turn it into a one-liner that's fine by me. :-) #!/usr/local/bin/perl # usage: zeller yyyy mm dd $day = &weekday(@ARGV); print $day,"\n"; sub weekday { local($year,$month,$day)=@_; local($y,$m,$c,$yy,$z); local(@wday) = ( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ); $y = $year; $m = ($month + 10) % 12; $y-- if ($m > 10); $c = int ( $y / 100 ); $yy = $year % 100; $z = ( int ( (26*$m - 2)/10) + $day + $yy + int($yy/4) + int ($c/4) - 2*$c ) % 7; return $wday[$z]; } -- Carl Rigney cdr@amd.com {ames decwrl sun uunet}!amdcad!cdr "There are no problems in perl, only opportunities for adventure."