diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php index 60df1de6cc..5eaed9de59 100644 --- a/webapp/src/Twig/TwigExtension.php +++ b/webapp/src/Twig/TwigExtension.php @@ -205,13 +205,20 @@ public function printelapsedminutes(float $start, float $end): string * Print a time formatted as specified. The format is according to date(). * @param Contest|null $contest If given, print time relative to that contest start. */ - public function printtime(string|float|null $datetime, ?string $format = null, ?Contest $contest = null): string + public function printtime(string|float|null $datetime, ?string $format = null, ?Contest $contest = null, bool $squash = true): string { if ($datetime === null) { $datetime = Utils::now(); } if ($contest !== null && $this->config->get('show_relative_time')) { $relativeTime = $contest->getContestTime((float)$datetime); + if ($relativeTime < 0 && $squash) { + return "Before contest"; + } + if ($relativeTime > $contest->getContestTime($contest->getEndtime())) { + // The case where it would be exactly at EndTime is important to display + return "After contest"; + } $sign = ($relativeTime < 0 ? -1 : 1); $relativeTime *= $sign; // We're not showing seconds, while the last minute before