Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found