Add support for %d %b %Y %T %Z format

Essentially HTTP format without the day and allowing any timezone.
master
Ben Moon 2016-01-15 15:06:45 +00:00
parent a24b0aaf42
commit db88b11d1d
2 changed files with 10 additions and 0 deletions

View File

@ -326,6 +326,9 @@ sub build_datestring_regex {
# HTTP: Sat, 09 Aug 2014 18:20:00
push @regexes, qr#$short_day_of_week, [0-9]{2} $short_month $full_year $time_24h?#i;
# HTTP (without day) any TZ: 09 Aug 2014 18:20:00 UTC
push @regexes, qr#[0-9]{2} $short_month $full_year $time_24h(?: ?$tz_suffixes)?#i;
# RFC850 08-Feb-94 14:15:29 GMT
push @regexes, qr#[0-9]{2}-$short_month-(?:[0-9]{2}|$full_year) $time_24h?(?: ?$tz_suffixes)#i;
@ -385,6 +388,7 @@ sub parse_formatted_datestring_to_date {
$d =~ s/,//i; # Strip any random commas.
$d =~ s/($full_month)/$full_month_to_short{lc $1}/i; # Parser deals better with the shorter month names.
$d =~ s/^($short_month)$date_delim(\d{1,2})/$2-$short_month_fix{lc $1}/i; # Switching Jun-01-2012 to 01 Jun 2012
$d =~ s/($tz_strings)$/$tz_offsets{$1}/i; # Convert trailing timezones to actual offsets.
my $maybe_date_object = try { DateTime::Format::HTTP->parse_datetime($d) }; # Don't die no matter how bad we did with checking our string.

View File

@ -94,6 +94,12 @@ subtest 'Dates' => sub {
'Sun Sep 7 20:11:44 BST 2014' => 1410117104,
# RFC 2822
'Sat, 13 Mar 2010 11:29:05 -0800' => 1268508545,
# HTTP (without day) - any TZ
# %d %b %Y %H:%M:%S %Z
'01 Jan 2012 00:01:20 UTC' => 1325376080,
'22 Jun 1998 00:00:02 UTC' => 898473602,
'07 Sep 2014 20:11:44 BST' => 1410117104,
'09 Aug 2014 18:20:00' => 1407608400,
#Undefined/Natural formats:
'13/12/2011' => 1323734400, #DMY
'01/01/2001' => 978307200, #Ambiguous, but valid