> > I was thinking about DateTime::Format::ISO8601... unless you have laid
> > claim to it.
This is the namespace I started on in March but whatever does ISO8601 should go there.
> Perhaps one of you should add it to the CVS server as-is and both work
> on it?
I haven't worked on this since the beginning of April. I believe this is most of the
date specifications - not including the week formats. Week and UTC offset handling,
time formats, and date + time formats are left (actually shouldn't be that bad).
Although I don't remember why I stopped working on this.
-J
--
package DateTime::Format::ISO8601;
use strict;
use DateTime::Format::Builder;
DateTime::Format::Builder->create_class(
parsers => {
parse_datetime => [
{
#YYYYMMDD 19850412
#YYYY-MM-DD 1985-04-12
regex => qr/^ (\d{4}) -?? (\d\d) -?? (\d\d) $/x,
params => [ qw( year month day ) ],
},
{
#YYYY-MM 1985-04
regex => qr/^ (\d{4}) -?? (\d\d) $/x,
params => [ qw( year month ) ],
},
{
#YYYY 1985
regex => qr/^ (\d{4}) $/x,
params => [ qw( year ) ],
},
{
#YY 85
# needs promotion to four digits
regex => qr/^ (\d\d) $/x,
params => [ qw( year ) ],
postprocess => \&_fix_2_digit_year,
},
{
#YYMMDD 850412
#YY-MM-DD 85-04-12
regex => qr/^ (\d\d) -?? (\d\d) -?? (\d\d) $/x,
params => [ qw( year month day ) ],
},
{
#-YYMM -8504
#-YY-MM -85-04
regex => qr/^ - (\d\d) -?? (\d\d) $/x,
params => [ qw( year month ) ],
postprocess => \&_fix_2_digit_year,
},
{
#-YY -85
# needs promotion to four digits
regex => qr/^ - (\d\d) $/x,
on_match => \&fix_year,
params => [ qw( year ) ],
postprocess => \&_fix_2_digit_year,
},
{
#--MMDD --0412
#--MM-DD --04-12
regex => qr/^ -- (\d\d) -?? (\d\d) $/x,
params => [ qw( month day ) ],
},
{
#--MM --04
regex => qr/^ -- (\d\d) $/x,
params => [ qw( month ) ],
},
{
#---DD ---12
regex => qr/^ --- (\d\d) $/x,
params => [ qw( day ) ],
},
{
#YYYYDDD 1985102
#YYYY-DDD 1985-102
regex => qr/^ (\d{4}) -?? (\d{3}) $/x,
params => [ qw( year day ) ],
},
{
#+[Y+]YYYYDDD +001985102
#+[Y+]YYYY-DDD +001985-102
regex => qr/^ \+ (\d{4,}) -?? (\d{3}) $/x,
params => [ qw( year day ) ],
},
],
}
);
# from DT::F::MySQL
sub _fix_2_digit_year {
my %p = @_;
$p{parsed}{year} += $p{parsed}{year} <= 69 ? 2000 : 1900;
}
1;
__END__