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

Re^3: Calculate Age, days to next and days from last for a given birthday

by davidrw (Prior)
on Apr 28, 2006 at 22:00 UTC ( [id://546417]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Calculate Age, days to next and days from last for a given birthday
in thread Calculate Age, days to next and days from last for a given birthday

We only ever work with the current year (plus or minus one).
Which by definition includes the Feb/Mar boundry, so leap year can affect it by a day...
I don't recall what the rules are regarding the 'leap year skip',
See the google link above (searched for 'leap year calculation'); Also another reason to use Date::Calc, Date::Time, etc modules.
but I'm pretty sure it won't affect this code for a very long time.
Yeah.. i'm pretty sure that's what people said about the year 2000, which came and went, as will 2038 .. as will 2100 (which has only 28 days in Feb) .. Sure, that's a little way off, but on prinicpal you should care about the accuracy of your code, also, what about this realistic (at least plausible) scenario: Someone sees your snippet here and adapts it to their code, which isn't limited to the current year (e.g. days to/from a certain future date) and 2100 might be a valid input ..

Replies are listed 'Best First'.
Re^4: Calculate Age, days to next and days from last for a given birthday
by ruzam (Curate) on Apr 29, 2006 at 05:03 UTC
    I thought the category 'fun stuff' was obvious....

    I take great pride in my code (even if it's sometimes wrong).

    I also spent the better part of 1997 thru 1999 fixing broken mainframe date code for a living. If you want to compare a 30 year old 2 digit year problem to a 100 year old leap year problem I think there's a baby/bath-water comparison that could be made. For all you know, by 2100 the leap year rule may be changed into another exception just to prevent computer leap year problems from popping up! (if we're even using the same calendar system by then)

    The code I've written here specifically uses current date +/- 1 year. Without rewriting portions of it, it will never see 1900. You, me and everything we know and believe about computers will be long since dead and turned to dust before this code ever sees 2100. So the scenario of someone using this snippet untouched for either of those years is not even a probability. That's the beauty of the 2000 'exception'.

    The code as written (pending some revisions) will happily work with any birthdate of any year. You can use any number that Perl will accept for the birthdate year, it isn't even passed to a date function of any kind. There is no provision to provide any date other than the current date. To make such a modification would require more careful attention to leap years as you've suggested. It would also not be the code I wrote.

    The point of my writing it was to avoid using Date::Calc. If Date::Calc were a core module I might have considered it first but it's not. There are times when you can't just pick the module of your dreams and toss it into the script.

Log In?
Username:
Password:

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

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

    No recent polls found