fix: 'Timer' logic

This commit is contained in:
2026-08-11 20:59:21 +08:00
parent 0b359ee4e2
commit bfb45a971e
5 changed files with 59 additions and 59 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "common"
description = "Commonly reusable code"
version = "0.1.19"
version = "0.1.20"
requires-python = ">=3.13"
authors = [
{ name="BreakerBear", email="breakerbear@autistic.men" },
+6 -6
View File
@@ -6,17 +6,17 @@ class Timer:
self.clear()
def clear(self):
self.checkpoint = None
self.accumulator = 0
self.checkpoint = 0
def start(self):
seconds = floor(time())
self.checkpoint = seconds
self.accumulator = self.delta()
self.checkpoint = floor(time())
def pause(self):
assert self.checkpoint is not None, "Uninitialized"
self.accumulator = self.delta()
self.checkpoint = 0
def delta(self):
assert self.checkpoint is not None, "Uninitialized"
return floor(time()) - self.checkpoint + self.accumulator
excess = floor(time()) - rhs if (rhs := self.checkpoint) else 0
return excess + self.accumulator