e
This commit is contained in:
parent
6423523d0c
commit
00000d9aee
1 changed files with 10 additions and 10 deletions
|
|
@ -15,20 +15,24 @@ class Time(datetime):
|
|||
|
||||
@classmethod
|
||||
def now(cls) -> "Time":
|
||||
dt = datetime.now(cls.TZ)
|
||||
return cls.fromtimestamp(dt.timestamp(), tz=cls.TZ)
|
||||
return cls.from_ts(datetime.now(cls.TZ).timestamp())
|
||||
|
||||
@classmethod
|
||||
def from_ts(cls, ts: int | float) -> "Time":
|
||||
return cls.fromtimestamp(ts, tz=cls.TZ)
|
||||
|
||||
def delta(self, **kwargs) -> "Time":
|
||||
new_dt = super().__add__(timedelta(**kwargs))
|
||||
return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo)
|
||||
return self.from_ts((self + timedelta(**kwargs)).timestamp())
|
||||
|
||||
def clean(self) -> "Time":
|
||||
new_dt = super().replace(second=0, microsecond=0)
|
||||
return self.__class__.fromtimestamp(new_dt.timestamp(), tz=new_dt.tzinfo)
|
||||
return self.__class__.fromtimestamp(
|
||||
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
|
||||
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)
|
||||
|
||||
def to_tz(self, tzone: str) -> "Time":
|
||||
dt = self.astimezone(ZONES[tzone])
|
||||
return self.__class__.fromtimestamp(dt.timestamp(), tz=ZONES[tzone])
|
||||
|
||||
|
||||
class Leagues:
|
||||
def __init__(self) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue