diff --git a/table.php b/table.php index 90cf90e..5965071 100644 --- a/table.php +++ b/table.php @@ -3,7 +3,20 @@ date_default_timezone_set('UTC'); $GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-11-02T08:53:00+01"); $GLOBALS['number_of_controls'] = 3; -//declare(strict_types=1); +// Caching +header("Last-Modified: " . date("F d Y H:i:s.", filemtime("passering.csv"))); +$etag = '"' . md5_file("passering.csv"). '"'; +header(header: 'ETag: ' . $etag ); + +if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) { + // If HTTP_IF_NONE_MATCH is same as the generated ETag => content is the same as browser cache + // So send a 304 Not Modified response header and exit + if($_SERVER['HTTP_IF_NONE_MATCH'] == $etag) { + header('HTTP/1.1 304 Not Modified', true, 304); + exit(); + } +} + class Runner { public int $id; @@ -92,6 +105,9 @@ function filter_runners(Runner $runner, $id) { } } +function time_diff(DateTime $date_1, DateTime $date_2) { + return $date_2->getTimestamp() - $date_1->getTimestamp(); +} $runners = []; $csv_runners = file_get_contents("db.csv"); @@ -220,6 +236,7 @@ else {
" . number_format(100*(time_diff($GLOBALS['start_time'],$runner->splits[2]) - time_diff($GLOBALS['start_time'],$runner->splits[1])) / time_diff($GLOBALS['start_time'],$runner->splits[2]), 0) . "% | "; + } + catch (DivisionByZeroError $e){ + $sprekk = ""; + } + catch (TypeError $e) { + $sprekk = " | "; + } } $matposter = " | $tid_1_mat | $tid_2_mat | "; } else { $mini_num++; } - $tid_maal = ""; - if ($runner->splits[2] != false) { - $tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S'); - } + if ($runner->course == "Kadaverløpet") { - $kadaver_table .= "
". $kadaver_num .". | $runner->name | $matposter$tid_maal |
". $kadaver_num .". | $runner->name | $matposter$tid_maal | $sprekk
". "" .". | $runner->name | $tid_maal |