You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a number of pages I'm trying to sort by the 'date' field (descending), with some being dates before 1970 and thus being represented by a negative timestamp (though valid as the dates are between 1965 and 1970). Grav is sorting that collection like so:
124141560
97531320
63664260
-148637760
-111733800
-31294320
-28268880
As you can see, the four negative timestamps are sorted in reverse. I've worked out that this is because Grav is sorting using the SORT_REGULAR flag, meaning it is first sorting the numbers as strings and then as a numbers. Changing lines 1204-1207 in Pages.php from:
case 'date':
$list[$key] = $child->date();
$sort_flags = SORT_REGULAR;
break;
to:
case 'date':
$list[$key] = $child->date();
$sort_flags = SORT_NUMERIC;
break;
leads to these dates to be ordered correctly.
I have tried using a call to order() with the 1 constant (as detailed by Flavio here #1199 (comment)), but the constant doesn't take effect because I'm sorting on date and thus the switch at line 1200 in Pages.php always sets the flag to SORT_REGULAR.
As date is represented by a number, shouldn't that line in the switch always be set to SORT_NUMERIC? If not, is there another fix?
I'm running Grav 1.3.10.
The text was updated successfully, but these errors were encountered:
it actually sounds like it should be fixed in Grav itself. date should always be numeric, and therefore, should be sorted as such. I'll fix in 1.4 branch.
I have a number of pages I'm trying to sort by the 'date' field (descending), with some being dates before 1970 and thus being represented by a negative timestamp (though valid as the dates are between 1965 and 1970). Grav is sorting that collection like so:
As you can see, the four negative timestamps are sorted in reverse. I've worked out that this is because Grav is sorting using the
SORT_REGULAR
flag, meaning it is first sorting the numbers as strings and then as a numbers. Changing lines 1204-1207 in Pages.php from:to:
leads to these dates to be ordered correctly.
I have tried using a call to
order()
with the1
constant (as detailed by Flavio here #1199 (comment)), but the constant doesn't take effect because I'm sorting ondate
and thus the switch at line 1200 in Pages.php always sets the flag toSORT_REGULAR
.As
date
is represented by a number, shouldn't that line in the switch always be set toSORT_NUMERIC
? If not, is there another fix?I'm running Grav 1.3.10.
The text was updated successfully, but these errors were encountered: