fix: 'Timer' logic
This commit is contained in:
+1
-1
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user