For some time now, I've been trying to figure out how
to calculate how many days left before a given date
of birth, to easily keep track of my friends' birthdays.
After a rather hairy PostgreSQL function and a few
beers, I decided to move the calculation from SQL to
Perl, and found the DateTime package, which seemed
interesting, but looking through the FAQ and documentation,
I couldn't see any _quick_ ways of doing what I want:

For any given date on ISO format (CCYY-MM-DD), calculate
how many days until this date while:

-keeping the year "circular", i.e. there are 364 days
 from now to 2006-02-24. ("now"==2005-02-26)
-keeping track of leap years, i.e. if now==1999-03-02,
 there are 365 days from now to 1980-03-01. (Since year
 2000 is a leap year.)
-(not very challenging, this one:) emulating people who
 were born on February 29th so that they will actually
 have birthdays in non-leap years as well.

The bottom line is that I'd like to have a program tell
me about an upcoming birthday n days in advance, and
preferably with an accurate measure.

I could do this with a bunch of conditional statements
for whether this year or that, (or even the upcoming year)
are leap-years, etc. However, if DateTime has some tricks
up its sleeves, I'd be very happy to hear about it.

Sven

Reply via email to