aboutsummaryrefslogtreecommitdiff
path: root/ppad/lib
diff options
context:
space:
mode:
authorNao Ueda <nao.uedder@gmail.com>2021-01-05 18:11:55 +0900
committerNao Ueda <nao.uedder@gmail.com>2021-01-05 18:11:55 +0900
commit2f2a1113e1acd5ede5d3966b9c42a7f479704811 (patch)
tree89c44b986146005788837c910e28c82fcc89b5b9 /ppad/lib
parent9a13b97b98a39ab0a8b9c62b46b8c2804485c1fe (diff)
downloadppad-2f2a1113e1acd5ede5d3966b9c42a7f479704811.tar.gz
ppad-2f2a1113e1acd5ede5d3966b9c42a7f479704811.tar.bz2
ppad-2f2a1113e1acd5ede5d3966b9c42a7f479704811.zip
move a function and rename it.
Diffstat (limited to 'ppad/lib')
-rw-r--r--ppad/lib/util.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/ppad/lib/util.py b/ppad/lib/util.py
index e857389..0a97141 100644
--- a/ppad/lib/util.py
+++ b/ppad/lib/util.py
@@ -4,7 +4,7 @@ import pytz
import time
-def date_parse(date: str) -> datetime:
+def parse_date(date: str) -> datetime:
dt = parser.isoparse(date)
if dt.tzinfo is not None:
@@ -12,3 +12,34 @@ def date_parse(date: str) -> datetime:
default_tz = pytz.timezone(time.tzname[time.daylight])
return default_tz.localize(dt)
+
+
+def parse_argv(argv: list[str]) -> tuple[datetime, datetime]:
+ if len(argv) == 1:
+ return None, None
+
+ date_to: datetime = None
+ date_from: datetime = None
+ from_str: str
+ to_str: str
+
+ span = argv[1].split('~')
+ if len(span) == 1:
+ from_str = to_str = span[0]
+ else:
+ [from_str, to_str, *_] = span
+
+ if from_str:
+ date_from = parse_date(from_str)
+
+ if to_str:
+ date_to = parse_date(to_str)
+
+ if date_from is None and date_to is None:
+ # probably `argv` would be only character '~'
+ return None, None
+
+ if date_from == date_to:
+ date_to = date_to + datetime.timedelta(days=1)
+
+ return date_from, date_to