akkudoktoreos.utils.datetimeutil.to_time
- akkudoktoreos.utils.datetimeutil.to_time(value: str | int | float | Tuple[int, ...] | Time | time | datetime | Time | DateTime, in_timezone: str | Timezone | None = None, to_naive: bool = False, as_string: Literal[False, None] = None) Time
- akkudoktoreos.utils.datetimeutil.to_time(value: str | int | float | Tuple[int, ...] | Time | time | datetime | Time | DateTime, in_timezone: str | Timezone | None = None, to_naive: bool = False, as_string: str | Literal[True] = None) str
Convert a time-like value into a timezone-aware Time object or formatted string.
- Parameters:
value – A time representation. Supports: - Time - pendulum.Time or pendulum.DateTime - datetime.time or datetime.datetime - strings like “14:30”, “2:30 PM”, “1430”, “14:30:00.123”, “2PM”, “14h30” - int (e.g. 14 → 14:00) - float (e.g. 14.5 → 14:30) - tuple like (14,), (14, 30), (14, 30, 15)
in_timezone – Optional timezone name or object (e.g., “Europe/Berlin”). Defaults to the local timezone.
to_naive – If True, return a timezone-naive Time object.
as_string – If True, return time as “HH:mm:ss ZZ”. If a format string is provided, it’s passed to pendulum.Time.format().
- Returns:
A time object or its formatted string.
- Return type:
Time or str
- Raises:
ValueError – If the input cannot be interpreted as a valid time.
TypeError – If timezone is not a valid type.