Eron Anon Eron Anon - 2 years ago 90
Perl Question

Error when dealing with old and historical dates in Perl Time::Piece

It seems

gives me this error:
Error parsing time at /usr/lib/perl5/site_perl/Time/ line 481.

after the line where I use
with some old dates.

My code contains this:

my $ddate = "$month / $day / $year";
my $tmp = Time::Piece->strptime( $ddate, "%m / %d / %Y");

and $$date takes dates from a database using DBI that contains historical and old dates (dates back to the 10th and 9th centuries AD). How can I deal with this if there is any solution?

Answer Source

You'll have to use something other than Time::Piece if you want to deal with timestamps before 1970. DateTime supports those (though time zone data might be sketchy if you go too far back).

Based on this historical calendar site, the Julian calendar was used prior to 1582. DateTime::Calendar::Julian provides better results for these dates.

$ perl -MDateTime -E'
      DateTime->new(year => 1013, month => 2, day => 22)

$ perl -MDateTime::Calendar::Julian -E'
      DateTime::Calendar::Julian->new(year => 1013, month => 2, day => 22)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download