summaryrefslogtreecommitdiff
path: root/jimbrella
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2021-10-22 23:26:19 +0800
committerFrederick Yin <fkfd@fkfd.me>2021-10-22 23:26:19 +0800
commita2059e127e4a41bc9d14e85527b834195da436c6 (patch)
treed3e628fa5b44618ea593b10c784c6a99e39fbe26 /jimbrella
parent3044005c2e45b6b5513b45a7e229ccdad3d8068c (diff)
UTC+8 timezone object
Diffstat (limited to 'jimbrella')
-rw-r--r--jimbrella/utils.py21
1 files changed, 20 insertions, 1 deletions
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)