Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Module Code Review

by japhy (Canon)
on Sep 15, 2001 at 04:24 UTC ( [id://112585]=note: print w/replies, xml ) Need Help??


in reply to Module Code Review

Your leap year calculation is incorrect. 2004 is a leap year, 2000 is a leap year, 1904 is a leap year, but 1900 is NOT. The rule is:
  • divisible by 4, and
  • not divisible by 100, or
  • divisible by 400
if (!($y % 4) and ($y % 100 or !($y % 400))) { ... }
Other than that, here's a much simpler method for finding out yesterday:
use Time::Local; my $noon = timelocal(0,0,12, (localtime)[3,4,5]); my ($d,$m,$y) = (localtime($noon - 86400))[3,4,5];

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
(tye)Re: Module Code Review
by tye (Sage) on Sep 15, 2001 at 09:58 UTC

    You don't even need Time::Local,

    my $yesterday= do { my($y,$m,$d)= (localtime( time-60*60*(12+(localtime)[2]) ))[5,4,3]; sprintf "%04d-%02d-%02d", 1900+$y, 1+$m, $d; };
    or, just for fun:
    my $yesterday= join"-",mapcar{sprintf "%0".shift()."d",pop()+pop()} [4,2,2],[(localtime( time-60*60*(12+(localtime)[2]) ))[5,4,3]],[1900,1,0];

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://112585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-03-28 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found