Skip to content

Commit f5125f4

Browse files
committed
Change strategy to get running event, use time instead of running status
1 parent 73a69d7 commit f5125f4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/Context/EitServiceAggregator.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use PhpBg\DvbPsi\Tables\Eit;
3131
use PhpBg\DvbPsi\Tables\EitEvent;
3232
use PhpBg\DvbPsi\Tables\Identifier;
33-
use PhpBg\DvbPsi\Tables\Values\EitRunningStatus;
3433

3534
/**
3635
* Class EitServiceAggregator
@@ -125,23 +124,26 @@ public function add(Eit $eit): bool
125124
}
126125

127126
/**
128-
* Return current running event
127+
* Return running event at a specified timestamp, which defaults to now
129128
*
130129
* @return EitEvent|null
130+
* @param int $timestamp
131131
*/
132-
public function getRunningEvent()
132+
public function getRunningEvent(int $timestamp = null)
133133
{
134-
if (empty($this->followingEvents)) {
135-
return null;
134+
if (!isset($timestamp)) {
135+
$timestamp = time();
136136
}
137-
$runningStatus = EitRunningStatus::RUNNING();
138-
foreach ($this->followingEvents as $eitevent) {
139-
/**
140-
* @var EitEvent $eit
141-
*/
142-
if ($runningStatus->equals($eitevent->getRunningStatus())) {
143-
return $eitevent;
137+
foreach ($this->getAllEvents() as $event) {
138+
if ($event->startTimestamp > $timestamp) {
139+
// Future event
140+
continue;
141+
}
142+
if ($event->startTimestamp + $event->duration < $timestamp) {
143+
// Past event
144+
continue;
144145
}
146+
return $event;
145147
}
146148
return null;
147149
}

0 commit comments

Comments
 (0)