Source code for timApp.admin.datetimetype

from datetime import datetime
from typing import Any

import click
import dateutil.parser


[docs]class DateTimeType(click.ParamType): """A better datetime type to use with Click.""" name = "datetime"
[docs] def convert(self, value: Any, param: Any, ctx: Any) -> datetime: try: return dateutil.parser.parse(value) except (ValueError, OverflowError) as e: return self.fail(str(e), param, ctx)