Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test a few more special cases
  • Loading branch information
kraih committed Feb 11, 2015
1 parent 0ea6b5d commit 1502135
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Date.pm
Expand Up @@ -28,7 +28,7 @@ sub parse {
# RFC 850/1036 (Sunday, 06-Nov-94 08:49:37 GMT)
my $offset = 0;
my ($day, $month, $year, $h, $m, $s);
if ($date =~ /^\w+\,\s+(\d+)\W+(\w+)\D+(\d+)\s+(\d+):(\d+):(\d+)\s+\w+$/) {
if ($date =~ /^\w+\,\s*(\d+)\W+(\w+)\D+(\d+)\s+(\d+):(\d+):(\d+)\s+\w+$/) {
($day, $month, $year, $h, $m, $s) = ($1, $MONTHS{$2}, $3, $4, $5, $6);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -49,7 +49,7 @@ my %XML = (
);

# "Sun, 06 Nov 1994 08:49:37 GMT" and "Sunday, 06-Nov-94 08:49:37 GMT"
my $EXPIRES_RE = qr/(\w+\,\s+\d+\W+\w+\D+\d+\s+\d+:\d+:\d+\s+\w+)/;
my $EXPIRES_RE = qr/(\w+\,\s*\d+\W+\w+\D+\d+\s+\d+:\d+:\d+\s+\w+)/;

# Encoding cache
my %CACHE;
Expand Down
18 changes: 12 additions & 6 deletions t/mojo/date.t
Expand Up @@ -9,6 +9,12 @@ is $date->epoch, 784111777, 'right epoch value';
$date = Mojo::Date->new('Fri, 13 May 2011 10:00:24 GMT');
is $date->epoch, 1305280824, 'right epoch value';

# RFC 850/1036
is(Mojo::Date->new('Sunday, 06-Nov-94 08:49:37 GMT')->epoch,
784111777, 'right epoch value');
is(Mojo::Date->new('Friday, 13-May-11 10:00:24 GMT')->epoch,
1305280824, 'right epoch value');

# RFC 3339
is(Mojo::Date->new('2014-08-20T20:45:00')->epoch,
1408567500, 'right epoch value');
Expand All @@ -30,16 +36,16 @@ is(Mojo::Date->new('1994-11-06T08:49:37Z')->epoch,
784111777, 'right epoch value');
is(Mojo::Date->new('1994-11-06t08:49:37.33z')->epoch,
784111777.33, 'right epoch value');
is(Mojo::Date->new('2014-08-20 20:45:00')->epoch,
1408567500, 'right epoch value');
is(Mojo::Date->new(784111777.33)->to_datetime,
'1994-11-06T08:49:37.33Z', 'right format');

# RFC 850/1036
is(Mojo::Date->new('Sunday, 06-Nov-94 08:49:37 GMT')->epoch,
# Special cases
is(Mojo::Date->new('Sun, 06-Nov-1994 08:49:37 UTC')->epoch,
784111777, 'right epoch value');
is(Mojo::Date->new('Friday, 13-May-11 10:00:24 GMT')->epoch,
1305280824, 'right epoch value');
is(Mojo::Date->new('Sunday,06 Nov 94 08:49:37 UTC')->epoch,
784111777, 'right epoch value');
is(Mojo::Date->new('2014-08-20 20:45:00')->epoch,
1408567500, 'right epoch value');

# ANSI C asctime()
is(Mojo::Date->new('Sun Nov 6 08:49:37 1994')->epoch,
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/util.t
Expand Up @@ -98,6 +98,10 @@ is_deeply split_cookie_header(
'a=b; expires=Tuesday, 09-Nov-1999 23:12:40 GMT, c=d'),
[['a', 'b', 'expires', 'Tuesday, 09-Nov-1999 23:12:40 GMT'], ['c', 'd']],
'right result';
is_deeply split_cookie_header(
'a=b; expires=Sun,06 Nov 1994 08:49:37 UTC; path=/'),
[['a', 'b', 'expires', 'Sun,06 Nov 1994 08:49:37 UTC', 'path', '/']],
'right result';

# unindent
is unindent(" test\n 123\n 456\n"), "test\n 123\n456\n",
Expand Down

0 comments on commit 1502135

Please sign in to comment.