From 5d3e1ea49247b9e55406002a326445d8eb55345f Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Jan 2020 21:21:12 +0000 Subject: add 'date' command spec type --- src/utils/parse/spec.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/utils/parse') 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 } -- cgit v1.3.1-10-gc9f91