more strict delta parsing

This commit is contained in:
Alexander Nigl 2025-04-23 12:48:51 +02:00
parent 4ccabfc661
commit a1f58829a6

View File

@ -24,18 +24,19 @@ DATETIME_FORMAT = [
class DateTime(click.DateTime): class DateTime(click.DateTime):
def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]: def _try_to_convert_date(self, value: t.Any, format: str) -> t.Optional[datetime]:
try: try:
if format == DELTASECONDS and value[-1] == "s": if value[0] == "+":
return datetime.datetime.now() + datetime.timedelta( if format == DELTASECONDS and value[-1] == "s":
seconds=int(value[1:-1]) return datetime.datetime.now() + datetime.timedelta(
) seconds=int(value[1:-1])
if format == DELTAMINUTES and value[-1] == "m": )
return datetime.datetime.now() + datetime.timedelta( if format == DELTAMINUTES and value[-1] == "m":
minutes=int(value[1:-1]) return datetime.datetime.now() + datetime.timedelta(
) minutes=int(value[1:-1])
if format == DELTAHOURS and value[-1] == "h": )
return datetime.datetime.now() + datetime.timedelta( if format == DELTAHOURS and value[-1] == "h":
hours=int(value[1:-1]) return datetime.datetime.now() + datetime.timedelta(
) hours=int(value[1:-1])
)
if format == HOURS: if format == HOURS:
return datetime.datetime.combine( return datetime.datetime.combine(
datetime.datetime.now().date(), datetime.datetime.now().date(),