From a2059e127e4a41bc9d14e85527b834195da436c6 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Fri, 22 Oct 2021 23:26:19 +0800 Subject: UTC+8 timezone object --- jimbrella/utils.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'jimbrella') diff --git a/jimbrella/utils.py b/jimbrella/utils.py index 1535d76..e0e6f95 100644 --- a/jimbrella/utils.py +++ b/jimbrella/utils.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, tzinfo def human_datetime(time: datetime) -> str: @@ -16,3 +16,22 @@ def human_timedelta(delta: timedelta) -> str: hours = delta.seconds // 3600 minutes = (delta.seconds - (hours * 3600)) // 60 return days + f"{hours:0>2}:{minutes:0>2}" # zero-pad to two digits + + +class UTCPlus8(tzinfo): + def __init__(self): + super().__init__() + + def utcoffset(self, dt): + return timedelta(hours=8) + + def dst(self, dt): + return timedelta(0) + + def tzname(self, dt): + return "+8:00" + +utc_plus_8 = UTCPlus8() + +def local_now(): + return datetime.now(tz=utc_plus_8) -- cgit v1.2.3