This is a smaller module dependency-wise and should be easier-to-install
for folks with limited packaging systems or network/disk capacity.
We do not need very powerful date parsing, as bad date formats are
likely the work of spammers.
use DateTime::Format::Mail;
use CGI qw(escapeHTML);
use POSIX qw(strftime);
+use Date::Parse qw(strptime);
use constant DATEFMT => '%Y-%m-%dT%H:%M:%SZ';
-our $dt_parser = DateTime::Format::Mail->new(loose => 1);
# main function
# FIXME: takes too many args, cleanup
sub feed_date {
my ($date) = @_;
- my $dt = $dt_parser->parse_datetime($date);
- $dt ? $dt->strftime(DATEFMT) : 0;
+ my @t = eval { strptime($date) };
+
+ scalar(@t) ? strftime(DATEFMT, @t) : 0;
}
# returns 0 (skipped) or 1 (added)