前回の記事の最後に書いたとおり、DateTime::Calendar::Japanese::Era
の挙動がなんかおかしい。有り体に言って、明治より前の元号を指定すると正常に動かないのだ。例えば、こんなスクリプトを書くと……
#!/usr/bin/perl use utf8; use strict; use warnings; use DateTime::Format::Strptime; use DateTime::Calendar::Japanese::Era; binmode STDOUT => ":utf8"; my @ary = qw! 1861/4/27 1861/4/28 1864/4/24 1864/4/25 1865/6/22 1865/6/23 1868/10/22 1868/10/23 !; my $fmt = new DateTime::Format::Strptime( pattern => "%Y/%m/%d", ); for my $i ( @ary ) { my $d = $fmt->parse_datetime( $i ); my $era = DateTime::Calendar::Japanese::Era ->lookup_by_date( datetime => $d ); printf "%s => %s%d年\n", $i, $era->name, $d->year - $era->start->year + 1; }