Skip to content

[5.x] Fix bug {{ collection:previous|next }} in collection with date and time enabled #11670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
@@ -186,7 +186,11 @@ protected function addArrayOfWheres($column, $boolean, $method = 'where')

public function prepareValueAndOperator($value, $operator, $useDefault = false)
{
$loweredOperator = strtolower((string) $operator);
if ($operator instanceof DateTimeInterface) {
$loweredOperator = Carbon::parse($operator)->toDateTimeString();
} else {
$loweredOperator = strtolower((string) $operator);
}

if ($useDefault) {
return [$operator, '='];
28 changes: 28 additions & 0 deletions tests/Tags/Collection/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -437,6 +437,34 @@ public function it_can_get_previous_and_next_entries_in_a_dated_asc_collection_w
$this->assertEquals(['Danish'], $this->runTagAndGetTitles('newer')); // Alias of next when date:asc
}

/**
* https://github.com/statamic/cms/issues/11263
*/
#[Test]
public function it_can_get_previous_and_next_entries_in_a_dated_asc_collection_when_date_and_time_enabled()
{
$this->foods->dated(true)->save();
$blueprint = Blueprint::makeFromFields(['date' => ['type' => 'date', 'time_enabled' => true, 'time_seconds_enabled' => true]])->setHandle('test');
Blueprint::shouldReceive('in')->with('collections/foods')->once()->andReturn(collect([$blueprint]));

$this->makeEntry($this->foods, 'a')->date('2019-03-10-1250')->set('title', 'Apple')->save();
$this->makeEntry($this->foods, 'b')->date('2019-03-10-1251')->set('title', 'Banana')->save();
$this->makeEntry($this->foods, 'c')->date('2019-03-10-1252')->set('title', 'Carrot')->save();
$this->makeEntry($this->foods, 'd')->date('2019-03-10-1253')->set('title', 'Danish')->save();
$this->makeEntry($this->foods, 'e')->date('2019-03-10-1254')->set('title', 'Egg')->save();
$this->makeEntry($this->foods, 'f')->date('2019-03-10-1255')->set('title', 'Fig')->save();
$this->setTagParameters([
'in' => 'foods',
'current' => $this->findEntryByTitle('Carrot')->id(),
'order_by' => 'date:asc|title:asc',
'limit' => 1,
]);
$this->assertEquals(['Banana'], $this->runTagAndGetTitles('previous'));
$this->assertEquals(['Banana'], $this->runTagAndGetTitles('older')); // Alias of previous when date:desc
$this->assertEquals(['Danish'], $this->runTagAndGetTitles('next'));
$this->assertEquals(['Danish'], $this->runTagAndGetTitles('newer')); // Alias of next when date:asc
}

#[Test]
public function it_can_get_previous_and_next_entries_in_an_orderable_asc_collection()
{