parsing / formatting historical dates

F

friendly

I'm reading/re-writing data files with historical dates that go back
potentially to antiquity. e.g., one such has name, lifespan, birth
date/place,
death date/place as \t separated fields.

Galilei, Galileo 1564-1642 b: 15 Feb 1564, Pisa d: 8 Jan 1642,
Arcetri, Italy
Lalanne, Leon 1811-1892 b: Paris 3 Jul 1811 d:13 Mar 1892

I need to parse the dates and reformat them, e.g. in ISO 8601 --
'15 Feb 1564' => '1564-02-15'
I tried using Date:parse and Date:Format,

my ($name, $lived, $born, $died) = split(/\s?[\t]/);
if ($born) {
$born =~ s/^\s*b:\s+//;
($birthdate, $birthplace) = split(/,\s*/, $born, 2);
my $date = str2time($birthdate);
$birthdate = time2str("%Y-%m-%d", $date);
}

but, as I see now, this converts to seconds since the epoch, 1-
jan-1970,
so it can't work.

Are there other modules that deal with historical dates? Assume that
I don't need time values.

thanks
 
T

Thrill5

I'm reading/re-writing data files with historical dates that go back
potentially to antiquity. e.g., one such has name, lifespan, birth
date/place,
death date/place as \t separated fields.

Galilei, Galileo 1564-1642 b: 15 Feb 1564, Pisa d: 8 Jan 1642,
Arcetri, Italy
Lalanne, Leon 1811-1892 b: Paris 3 Jul 1811 d:13 Mar 1892

I need to parse the dates and reformat them, e.g. in ISO 8601 --
'15 Feb 1564' => '1564-02-15'
I tried using Date:parse and Date:Format,

my ($name, $lived, $born, $died) = split(/\s?[\t]/);
if ($born) {
$born =~ s/^\s*b:\s+//;
($birthdate, $birthplace) = split(/,\s*/, $born, 2);
my $date = str2time($birthdate);
$birthdate = time2str("%Y-%m-%d", $date);
}

but, as I see now, this converts to seconds since the epoch, 1-
jan-1970,
so it can't work.

Are there other modules that deal with historical dates? Assume that
I don't need time values.

thanks
Not sure why you need a module to do this. Have you over simplified the
problem?

my %months = (Jan => 1, Feb => 2, Mar => 3, Apr => 4,
May => 5, Jun => 6, Jul => 7, Aug => 8,
Sep => 9, Oct => 10, Nov => 11, Dec => 12);

sub convdate {
my ($day, $mon, $year) = split(/\s+/,shift);
return sprintf("%04d-%02d-%02d",$year,$months{$mon},$day);
}

my ($name, $lived, $born, $died) = split(/\s?[\t]/);
if ($born) {
$born =~ s/^\s*b:\s+//;
($birthdate, $birthplace) = split(/,\s*/, $born, 2);
$birthdate = convdate($birthdate);
}

Scott
 
U

usenet

I'm reading/re-writing data files with historical dates that go back
potentially to antiquity.

The Date::Manip module does not rely on epoch seconds to store its
objects. It will work for your purposes.
 
G

Gunnar Hjalmarsson

I need to parse the dates and reformat them, e.g. in ISO 8601 --
'15 Feb 1564' => '1564-02-15'
I tried using Date:parse and Date:Format,

my $date = str2time($birthdate);
$birthdate = time2str("%Y-%m-%d", $date);

Try this instead:

my ($d, $m, $y) = (strptime $birthdate)[3..5];
$birthdate = sprintf '%d-%02d-%02d', $y<1000 ? 1900+$y : $y, $m+1, $d;
but, as I see now, this converts to seconds since the epoch,
1-jan-1970, so it can't work.

The Date::parse::strptime() function does not have that limitation, at
least not on my Windows box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top