Open
Description
- Mojolicious version: any
- Perl version: any
- Operating system: any
Mojo::Date
objects stringify to RFC 7231 HTTP-date format. As a consequence sorting is kind of broken:
With string comparison operators their first sort attribute is the English week day name, and you get wrong results and warnings with numeric comparison.
Steps to reproduce the behavior
$> perl -MMojo::Date -wE 'say Mojo::Date->new("2020-10-15T00:00:00Z") cmp Mojo::Date->new("2020-10-16T00:00:00Z");'
1
$> perl -MMojo::Date -wE 'say Mojo::Date->new("2020-10-15T00:00:00Z") <=> Mojo::Date->new("2020-10-16T00:00:00Z");'
Argument "Fri, 16 Oct 2020 00:00:00 GMT" isn't numeric in numeric comparison (<=>) at -e line 1.
Argument "Thu, 15 Oct 2020 00:00:00 GMT" isn't numeric in numeric comparison (<=>) at -e line 1.
0
Expected behavior
$> perl -MMojo::Date -wE 'say Mojo::Date->new("2020-10-15T00:00:00Z") cmp Mojo::Date->new("2020-10-16T00:00:00Z");'
-1
$> perl -MMojo::Date -wE 'say Mojo::Date->new("2020-10-15T00:00:00Z") <=> Mojo::Date->new("2020-10-16T00:00:00Z");'
-1
Actual behavior
See Steps to reproduce the behavior
Suggested code change
Overload cmp
and <=>
with something like sub ($l, $r) { $l->epoch <=> $r->epoch }
(type check for $r omitted for brevity).