DateTime::Format::PGN - a Perl module for parsing and formatting date fields in chess game databases in PGN format
version 0.05
use DateTime::Format::PGN; my $f = DateTime::Format::PGN->new(); my $dt = $f->parse_datetime( '2004.04.23' ); # 2004.04.23 print $f->format_datetime( $dt ); # return a DateTime::Incomplete object: my $fi = DateTime::Format::PGN->new( { use_incomplete => 1} ); my $dti = $fi->parse_datetime( '2004.??.??' ); # 2004.??.?? print $fi->format_datetime( $dti );
Options are Boolean use_incomplete (default 0) and Boolean fix_errors (default 0).
use_incomplete
fix_errors
my $f = DateTime::Format::PGN->new( { fix_errors => 1, use_incomplete => 1 } );
PGN allows for incomplete dates while DateTime does not. All missing date values in DateTime default to 1. So PGN ????.??.?? becomes 0001.01.01 with DateTime. If use_incomplete => 1, a DateTime::Incomplete object is used instead where missing values are undef.
DateTime
????.??.??
0001.01.01
use_incomplete => 1
DateTime::Incomplete
undef
I observed a lot of mistaken date formats in PGN databases downloaded from the internet. If fix_errors => 1, an attempt is made to parse the date anyway.
fix_errors => 1
Returns a DateTime object or a DateTime::Incomplete object if option use_incomplete => 1. Since the first recorded chess game was played 1485, years with a leading 0 are handled as errors.
Given a DateTime object, this methods returns a PGN date string. If the date is incomplete, use a DateTime::Incomplete object (the use_incomplete option does not affect the formatting here).
PGN spec by Steven J. Edwards.
Chess::PGN::Parse
http://datetime.perl.org/
Ingram Braun <ibraun@cpan.org>
This software is copyright (c) 2016 by Ingram Braun.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DateTime::Format::PGN, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTime::Format::PGN
CPAN shell
perl -MCPAN -e shell install DateTime::Format::PGN
For more information on module installation, please visit the detailed CPAN module installation guide.