I found this jewel in Greg Hewgill's implementation of the cal command on the Perl Power Tools page:

http://www.perl.com/language/ppt/src/cal/index.html

YuckFoo

# DOW = ([23m/9] + d + 4 + z + [z/4] - [z/100] + [z/400] - 2 (if m>=3 +)) mod 7 # # y is the year. # m is the month. # d is the day. # z = y - 1 (if m < 3) # = y (if m >= 3) # A mod B means take the reminder of A / B. # # The source: Journal on Recreational Mathematics, Vol. 22(4), pages +280-282, 1990. # The authors: Michael Keith and Tom Craver. # # The formula can be implemented by the following C function: # # int dayofweek(int y,m,d) # { # return((23*m/9+d+4+(m<3?y--:y-2)+y/4-y/100+y/400)%7); # } sub dow { my ($y, $m, $d) = @_; $y-- if $m < 3; $d += 11 if $y < 1752 || $y == 1752 && $m < 9; if ($y >= 1752) { return (int(23*$m/9)+$d+4+($m<3?$y+1:$y-2)+int($y/4)-int($y/100)+i +nt($y/400))%7; } else { return (int(23*$m/9)+$d+5+($m<3?$y+1:$y-2)+int($y/4))%7; } }

In reply to Re: &bull;Day of week for an arbitary date using core modules by YuckFoo
in thread Day of week for an arbitary date using core modules by merlyn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.