From 9a13b97b98a39ab0a8b9c62b46b8c2804485c1fe Mon Sep 17 00:00:00 2001 From: Nao Ueda Date: Tue, 5 Jan 2021 18:07:25 +0900 Subject: fix date parsing, some refactor --- ppad/lib/__init__.py | 0 ppad/lib/util.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 ppad/lib/__init__.py create mode 100644 ppad/lib/util.py (limited to 'ppad/lib') diff --git a/ppad/lib/__init__.py b/ppad/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ppad/lib/util.py b/ppad/lib/util.py new file mode 100644 index 0000000..e857389 --- /dev/null +++ b/ppad/lib/util.py @@ -0,0 +1,14 @@ +import datetime +from dateutil import parser +import pytz +import time + + +def date_parse(date: str) -> datetime: + dt = parser.isoparse(date) + + if dt.tzinfo is not None: + return dt + + default_tz = pytz.timezone(time.tzname[time.daylight]) + return default_tz.localize(dt) -- cgit v1.2.3-54-g00ecf