This commit is contained in:
doms9 2025-10-29 03:21:18 -04:00
parent 8609c0a39e
commit 00000d90b7
11 changed files with 501 additions and 187 deletions

View file

@ -5,12 +5,16 @@ from pathlib import Path
import pytz
ZONES = {"ET": pytz.timezone("America/New_York"), "UTC": timezone.utc}
ZONES["EDT"] = ZONES["EST"] = ZONES["ET"]
class Time(datetime):
ZONES = {
"ET": pytz.timezone("America/New_York"),
"PST": pytz.timezone("America/Los_Angeles"),
"UTC": timezone.utc,
}
ZONES["EDT"] = ZONES["EST"] = ZONES["ET"]
TZ = ZONES["ET"]
@classmethod
@ -39,8 +43,8 @@ class Time(datetime):
)
def to_tz(self, tzone: str) -> "Time":
dt = self.astimezone(ZONES[tzone])
return self.__class__.fromtimestamp(dt.timestamp(), tz=ZONES[tzone])
dt = self.astimezone(self.ZONES[tzone])
return self.__class__.fromtimestamp(dt.timestamp(), tz=self.ZONES[tzone])
@classmethod
def from_str(
@ -49,16 +53,17 @@ class Time(datetime):
fmt: str | None = None,
) -> "Time":
pattern = re.compile(r"\b(ET|UTC|EST|EDT)\b")
pattern = re.compile(r"\b(ET|UTC|EST|EDT|PST)\b")
match = pattern.search(s)
tz = ZONES.get(match[1]) if match else cls.TZ
tz = cls.ZONES.get(match[1]) if match else cls.TZ
cleaned_str = pattern.sub("", s).strip()
if fmt:
dt = datetime.strptime(cleaned_str, fmt)
else:
formats = [
"%Y-%m-%d %H:%M",