This commit is contained in:
doms9 2025-10-02 13:19:44 -04:00
parent 6423523d0c
commit 00000d9aee

View file

@ -15,20 +15,24 @@ class Time(datetime):
@classmethod @classmethod
def now(cls) -> "Time": def now(cls) -> "Time":
dt = datetime.now(cls.TZ) return cls.from_ts(datetime.now(cls.TZ).timestamp())
return cls.fromtimestamp(dt.timestamp(), tz=cls.TZ)
@classmethod @classmethod
def from_ts(cls, ts: int | float) -> "Time": def from_ts(cls, ts: int | float) -> "Time":
return cls.fromtimestamp(ts, tz=cls.TZ) return cls.fromtimestamp(ts, tz=cls.TZ)
def delta(self, **kwargs) -> "Time": def delta(self, **kwargs) -> "Time":
new_dt = super().__add__(timedelta(**kwargs)) return self.from_ts((self + timedelta(**kwargs)).timestamp())
return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo)
def clean(self) -> "Time": def clean(self) -> "Time":
new_dt = super().replace(second=0, microsecond=0) return self.__class__.fromtimestamp(
return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo) self.replace(second=0, microsecond=0).timestamp(),
tz=self.TZ,
)
def to_tz(self, tzone: str) -> "Time":
dt = self.astimezone(ZONES[tzone])
return self.__class__.fromtimestamp(dt.timestamp(), tz=ZONES[tzone])
@classmethod @classmethod
def from_str(cls, s: str, fmt: str | None = None) -> "Time": def from_str(cls, s: str, fmt: str | None = None) -> "Time":
@ -63,10 +67,6 @@ class Time(datetime):
return cls.fromtimestamp(dt.astimezone(cls.TZ).timestamp(), tz=cls.TZ) return cls.fromtimestamp(dt.astimezone(cls.TZ).timestamp(), tz=cls.TZ)
def to_tz(self, tzone: str) -> "Time":
dt = self.astimezone(ZONES[tzone])
return self.__class__.fromtimestamp(dt.timestamp(), tz=ZONES[tzone])
class Leagues: class Leagues:
def __init__(self) -> None: def __init__(self) -> None: