Skip to content

Commit

Permalink
Date(time) sorting does not take time into account (#295)
Browse files Browse the repository at this point in the history
* Take time into account when enabled for datetime sorting

* 🍺

---------

Co-authored-by: Ryan Mitchell <[email protected]>
  • Loading branch information
sylvesterdamgaard and ryanmitchell authored Jun 4, 2024
1 parent dc7851c commit a058ee3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Entries/EntryQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public function orderBy($column, $direction = 'asc')
} elseif (in_array($fieldType, ['integer'])) {
$castType = 'float'; // bit sneaky but mysql doesnt support casting as integer, it wants unsigned
} elseif (in_array($fieldType, ['date'])) {
$castType = 'date';
// Take time into account when enabled
if ($blueprintField->get('time_enabled')) {
$castType = 'datetime';
} else {
$castType = 'date';
}

// sqlite casts dates to year, which is pretty unhelpful
if (str_contains(get_class($grammar), 'SQLiteGrammar')) {
Expand Down

0 comments on commit a058ee3

Please sign in to comment.