more strict delta parsing
This commit is contained in:
parent
4ccabfc661
commit
a1f58829a6
25
timer.py
25
timer.py
@ -24,18 +24,19 @@ DATETIME_FORMAT = [
|
||||
class DateTime(click.DateTime):
|
||||
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
|
||||
try:
|
||||
if format == DELTASECONDS and value[-1] == "s":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
seconds=int(value[1:-1])
|
||||
)
|
||||
if format == DELTAMINUTES and value[-1] == "m":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
minutes=int(value[1:-1])
|
||||
)
|
||||
if format == DELTAHOURS and value[-1] == "h":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
hours=int(value[1:-1])
|
||||
)
|
||||
if value[0] == "+":
|
||||
if format == DELTASECONDS and value[-1] == "s":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
seconds=int(value[1:-1])
|
||||
)
|
||||
if format == DELTAMINUTES and value[-1] == "m":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
minutes=int(value[1:-1])
|
||||
)
|
||||
if format == DELTAHOURS and value[-1] == "h":
|
||||
return datetime.datetime.now() + datetime.timedelta(
|
||||
hours=int(value[1:-1])
|
||||
)
|
||||
if format == HOURS:
|
||||
return datetime.datetime.combine(
|
||||
datetime.datetime.now().date(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user