As you can see in my (newly added) code, I work with *local* dates using timegm+gmtime. The number of days bewteen two dates is the same no matter which time zone you are in.
| [reply] |
OK, I see now how your code works works (took me a while, sorry). But I'm still confused as to the need to convert to seconds.
my $days = (localtime)[7];
$days will be correct for the current date regardless of the time or DST no? All other days are calculated as of 0:00:00 which should also be correct for any given date regardless of DST. Or am I missing something about the way localtime/timelocal work?
(living in a time zone with no DST does have it's disadvantages here).
I never thought of feb 29 birthdates failing as invalid dates in non-leap years! | [reply] [d/l] |
But I'm still confused as to the need to convert to seconds.
You can't do arithmetic on years+months+days. Just like you can't do arithmetic on degrees+minutes+seconds. You need to convert it into a number.
I could have converted every date into the number of days since an arbitrary day, but there's no existing function to do that (or the inverse operation). Doing it manually would force me to handle leap seconds, leap days, oddly numbered months, etc.
On the other hand, there's already a function (timegm) to convert a date into the number of seconds since an arbitrary second (Jan 1st, 1970, 0:00:00), and there's already a function which does the inverse operation (gmtime).
| [reply] |