2021-11-19 14:47:04 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2021-11-19 14:47:04 +00:00
|
|
|
class Stopwatch:
|
|
|
|
def __init__(self):
|
2023-06-16 10:51:31 +00:00
|
|
|
self.reset()
|
2021-11-19 14:47:04 +00:00
|
|
|
|
|
|
|
@property
|
2023-01-03 11:55:12 +00:00
|
|
|
def duration_seconds(self) -> float:
|
2021-11-19 14:47:04 +00:00
|
|
|
return (datetime.datetime.utcnow() - self.start_time).total_seconds()
|
|
|
|
|
|
|
|
@property
|
2023-01-03 11:55:12 +00:00
|
|
|
def start_time_str(self) -> str:
|
2021-11-19 15:24:39 +00:00
|
|
|
return self.start_time_str_value
|
2023-06-16 10:51:31 +00:00
|
|
|
|
|
|
|
def reset(self) -> None:
|
|
|
|
self.start_time = datetime.datetime.utcnow()
|
|
|
|
self.start_time_str_value = self.start_time.strftime("%Y-%m-%d %H:%M:%S")
|