diff options
author | Stefanie Eckner <stefanie@eckner.net> | 2024-02-17 09:22:02 +0100 |
---|---|---|
committer | Stefanie Eckner <stefanie@eckner.net> | 2024-02-17 09:22:02 +0100 |
commit | 4ff09b9bbe7ace3f327e0314e193b78dd66f1c04 (patch) | |
tree | ac2d53ce5ec12acd89a840c93b97d7254713bba3 | |
parent | 87f2bb4aa8891b342542c9b1eb0f23908593b738 (diff) | |
download | computer-time-limit-4ff09b9bbe7ace3f327e0314e193b78dd66f1c04.tar.xz |
computer-time-limit.php: use a single time
-rw-r--r-- | computer-time-limit.php | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/computer-time-limit.php b/computer-time-limit.php index fd23b30..b81081d 100644 --- a/computer-time-limit.php +++ b/computer-time-limit.php @@ -1,10 +1,11 @@ <?php $db = new SQLite3('../backstage/computer-time-limit/computer-time-limit.sqlite'); +$now = time(); function log_to_file($line) { $handle = fopen('../backstage/computer-time-limit/log', 'a'); - fwrite($handle, time() . ' ' . $line . "\n"); + fwrite($handle, $now . ' ' . $line . "\n"); fclose($handle); } @@ -46,9 +47,9 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) { $aktiv = 0; $bis = $von; } - $bis = $bis + 30*60*(floor(time()/60/60/24) - floor($von/60/60/24)); + $bis = $bis + 30*60*(floor($now/60/60/24) - floor($von/60/60/24)); if ($aktiv) { - $von = time(); + $von = $now; } $noch = $bis - $von; if ($noch < 0) { @@ -76,8 +77,8 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) { if ($noch == 0) { $aktiv = 0; } - $von = date('Y-m-d H:i:s', time()); - $bis = date('Y-m-d H:i:s', time() + $noch); + $von = date('Y-m-d H:i:s', $now); + $bis = date('Y-m-d H:i:s', $now + $noch); log_to_file('to_db ' . $key . ' ' . $aktiv . ' ' . $von . ' ' . $bis); $db -> exec( 'UPDATE `computer_time`' . @@ -98,7 +99,7 @@ while ($row = $result->fetchArray()) { $bis = strtotime($row['bis']); $von = strtotime($row['von']); if ($row['aktiv']) { - $von = time(); + $von = $now; } $noch = $bis - $von; |