Skip to content

Instantly share code, notes, and snippets.

@theory
Created May 21, 2010 16:14
Show Gist options
  • Save theory/409035 to your computer and use it in GitHub Desktop.
Save theory/409035 to your computer and use it in GitHub Desktop.
my $parse_datetime = sub {
my $ts = shift or return undef;
return eval { DateTime::Format::W3CDTF->parse_datetime($ts) }
|| eval { DateTime::Format::ISO8601->parse_datetime($ts) }
|| eval { DateTime::Format::Flexible->parse_datetime($ts) }
|| do {
my $p = DateTime::Format::Natural->new;
my $dt = $p->parse_datetime($ts);
$p->success ? $dt : undef;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment