Anno said:
I don't remember saying it doesn't. It would be your job to prove
that it does, and (a lot harder) to describe the conditions under
which it does.
My "job"? You asked if I have "a simple, water-tight solution" using
only Time::Local, and I posted this code, which I claim is just that:
sub daysago {
shift =~ /^(\d{4})-(\d{2})-(\d{2})$/
or die "Invalid date format";
require Time::Local;
import Time::Local 'timelocal';
my $diff = timelocal(0,0,0,(localtime $^T)[3..5])
- timelocal(0,0,0,$3,$2-1,$1-1900);
$diff >= 0 or die "Future date not allowed";
sprintf '%.0f', $diff / 86400
}
print daysago('2003-07-20'), "\n";
It addresses the trivial task the OP asked for help with: Calculating
the number of days since a certain date.
My point is that the seemingly clear notion of the number of days
between two calendar dates must be re-defined in view of the fact
that two midnights aren't necessarily a multiple of 24 hours apart.
Re-defined? Out from which definition? And why?
The function computes the number of seconds between 00:00:00 at the
comparison date and 00:00:00 at today's date. Switching to or from DST
may result in that number being 3600 seconds less or more than a
multiple of 86400, but such a switch can never affect the full number
of calendar days after rounding by sprintf().
You assume that rounding is the answer, but other answers could be
given, which might differ by one under various circumstances.
Which answers would that be? Note that we are talking about comparing
dates. Time of the day is not an input, and should obviously not
affect the result.
At this point I might decide to use a module that (presumably) has
come up with a solution that is both consistent in itself and with
intuitive notions, and which is reasonably general with respect to
local DST variations.
Nothing wrong with doing so, of course. Personally I think twice
before using a non-standard module, since I usually work with programs
that are intended for distribution, and non-standard modules
complicates the distribution.