aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/utils/datetime/parse.py6
-rw-r--r--src/utils/parse/spec.py10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/datetime/parse.py b/src/utils/datetime/parse.py
index 8e372f8c..51941d78 100644
--- a/src/utils/datetime/parse.py
+++ b/src/utils/datetime/parse.py
@@ -6,6 +6,12 @@ from .common import *
def iso8601(s: str) -> _datetime.datetime:
return dateutil.parser.parse(s)
+def date_human(s: str) -> typing.Optional[_datetime.datetime]:
+ try:
+ return _datetime.datetime.strptime(s, DATE_HUMAN)
+ except ValueError:
+ return None
+
REGEX_PRETTYTIME = re.compile(
r"(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?", re.I)
diff --git a/src/utils/parse/spec.py b/src/utils/parse/spec.py
index 4e30c294..1aa24610 100644
--- a/src/utils/parse/spec.py
+++ b/src/utils/parse/spec.py
@@ -1,6 +1,7 @@
import enum, typing
from .time import duration
from .types import try_int
+from src.utils.datetime.parse import date_human
class SpecArgumentContext(enum.IntFlag):
CHANNEL = 1
@@ -67,6 +68,14 @@ class SpecArgumentTypeDuration(SpecArgumentType):
def error(self) -> typing.Optional[str]:
return "Invalid timeframe"
+class SpecArgumentTypeDate(SpecArgumentType):
+ def name(self):
+ return SpecArgumentType.name(self) or "yyyy-mm-dd"
+ def simple(self, args):
+ if args:
+ return date_human(args[0], 1)
+ return None, 1
+
class SpecArgumentPrivateType(SpecArgumentType):
context = SpecArgumentContext.PRIVATE
@@ -77,6 +86,7 @@ SPEC_ARGUMENT_TYPES = {
"string": SpecArgumentTypeString,
"tstring": SpecArgumentTypeTrimString,
"int": SpecArgumentTypeInt,
+ "date": SpecArgumentTypeDate,
"duration": SpecArgumentTypeDuration
}