Peter J. Acklam schreef:
> Why no year 0 in DateTime? I was surprised to see the following
> in the synopsis:
>
> $year = $dt->year; # there is no year 0
>
> The ISO8601 range is [0000,9999], thus including year 0. The
> standard even explicitly mentions that year 0 was a leap year.
There are two ways to count years: the first one is the original by
Dionysius Exiguus, which goes 3 BC, 2 BC, 1 BC, 1 AD, 2 AD etc. The
second one is the astronomical convention: -2, -1, 0, +1, +2. You can
imagine that this simplifies astronomical calculations. ISO8601 year 0
is the same as the year 1 BC.
ISO8601 obviously uses the astronomical convention. Dave evidently
uses the Dionysian reckoning. I think this is the correct choice: if I
want to create a date in 44BC, I'd prefer to say
$dt = DateTime->new( year => -44, month => 3, day => 'Ides' );
to
$dt = DateTime->new( year => -43, month => 3, day => 'Ides' );
One could say that ISO8601 is zero-based, while Dionisius was 1-based
(not surprisingly, as zero wasn't invented back then). For some strange
reason, the zero-based year in DateTime is defined as the (useless,
IMHO) function
sub year_0 { $_[0]->{c}{year} - 1 }
(DateTime uses astronomical convention internally) while I would have
defined it as the more useful and less surprising
sub year_0 { $_[0]->{c}{year} }
Interestingly, the function ymd (and therefore also iso8601) uses
astronomical years. Obviously correct for iso8601; I'm not sure about
ymd.
Eugene