Skip Menu |

This queue is for tickets about the Class-Date CPAN distribution.

Report information
The Basics
Id: 19715
Status: resolved
Priority: 0/
Queue: Class-Date

People
Owner: dlux [...] dlux.hu
Requestors: pauloscustodio [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.1.9
Fixed in: (no value)



Subject: Cannot parse an IS0 8601 date and time
An ISO 8601 date and time, as recommended by the W3C (http://www.w3.org/TR/NOTE-datetime), is represented as "YYYY-MM-DDThh:mm:ssTZD", with a "T" separating the date and the time part, but the Class::Date::new() method expects a blank instead. The attached patch makes the new() method accept either a blank (as in version 1.1.9) or a "T". This change allows me to parse an ISO date (without timezone) simply by Class::Date->new(ISO_DATE). Parsing also the timezone is probably easy, but I do not need it in this particular project. Best regards, Paulo Custodio
Subject: Class-Date-1.1.9.patch
*** Class/Date.pm.ori Sun May 14 21:34:29 2006 --- Class/Date.pm Mon Jun 5 20:07:09 2006 *************** *** 228,234 **** $obj->_recalc_from_epoch; return $obj; } elsif ($time =~ m{ ^\s* ( \d{0,4} ) - ( \d\d? ) - ( \d\d? ) ! ( \s+ ( \d\d? ) : ( \d\d? ) ( : ( \d\d? ) (\.\d+)?)? )? }x) { my ($y,$m,$d,$hh,$mm,$ss)=($1,$2,$3,$5,$6,$8); # ISO(-like) date return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss],$tz); --- 228,234 ---- $obj->_recalc_from_epoch; return $obj; } elsif ($time =~ m{ ^\s* ( \d{0,4} ) - ( \d\d? ) - ( \d\d? ) ! ( [\s|T]+ ( \d\d? ) : ( \d\d? ) ( : ( \d\d? ) (\.\d+)?)? )? }x) { my ($y,$m,$d,$hh,$mm,$ss)=($1,$2,$3,$5,$6,$8); # ISO(-like) date return $s->new_from_array([$y,$m,$d,$hh,$mm,$ss],$tz);
I second this patch. This is a serious deficiency in the parsing, since for iso dates it gets a partial success, returning the date without the time. This means it does not go on to try any other parsers, such as the ones added by the -DateParse option. I actually patched the module with (?:T|\s+) instead of [\s|T]+ which is what is in the patch. No need for multiple T's.
Hi, I updated the code with your patch. I added some tests for this, too. Thanks for the contribution! I'll do a release soon. Balázs On Thu Nov 06 18:55:27 2008, JWILLIAMS wrote: Show quoted text
> I second this patch. This is a serious deficiency in the parsing, since > for iso dates it gets a partial success, returning the date without the > time. This means it does not go on to try any other parsers, such as > the ones added by the -DateParse option. > > I actually patched the module with > > (?:T|\s+) > > instead of > > [\s|T]+ > > which is what is in the patch. No need for multiple T's.