added timestamping interface

This commit is contained in:
2023-01-16 12:27:31 +01:00
parent 4799790a16
commit f45eb215b3

View File

@ -0,0 +1,49 @@
import functools
from datetime import datetime
DEFAULT_NAMES = (
"creation",
"access",
"modification"
)
class Timestamps:
def __init__(self, names=DEFAULT_NAMES):
dt = datetime.now() # make sure all times are identical at the start
self.times = {n: Time(dt) for n in names}
self.__dict__.update(self.times)
def max(self):
return max(self.times.values())
def min(self):
return min(self.times.values())
def __repr__(self):
return repr(self.times)
@functools.total_ordering
class Time:
def __init__(self, dt=None):
self.dt = dt or datetime.now()
def update(self):
self.dt = datetime.now()
def __repr__(self):
return repr(self.dt)
def __eq__(self, other):
return (self.dt == other.dt)
def __lt__(self, other):
return (self.dt < other.dt)