Only past talks are counted
Talks at an event happening "today" haven't happened yet, so shouldn't be counted. A talk should only counted if it was given at a past event - i.e. yesterday or earlier. Previously a talk with today's date was returning a time of 00:00 and was being counted in the past count if the site was generated on the same day.
This commit is contained in:
parent
d2c2f791bd
commit
1a0101772f
|
@ -23,7 +23,7 @@ class OpdaviesTwigExtension extends AbstractExtension
|
|||
|
||||
public function getPastTalkCount(array $talks): int
|
||||
{
|
||||
$today = (new \DateTime())->getTimestamp();
|
||||
$today = (new \DateTime('today'))->getTimestamp();
|
||||
|
||||
return collect($talks)
|
||||
->flatMap(fn (ProxySourceItem $talk) => $talk->data()->get('events'))
|
||||
|
|
|
@ -90,6 +90,30 @@ class OpdaviesTwigExtensionTest extends TestCase
|
|||
$this->assertTalkCount(expectedCount: 2, talks: [$talkA, $talkB]);
|
||||
}
|
||||
|
||||
public function testTheCurrentDayIsNotCounted(): void
|
||||
{
|
||||
$talkA = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('yesterday'))->getTimestamp()],
|
||||
['date' => (new \DateTime('today'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
$talkB = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('today'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
$talkC = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('yesterday'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
$this->assertTalkCount(expectedCount: 2, talks: [$talkA, $talkB, $talkC]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the extension uses the correct number of talks.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue