LeadTime#
- class openstef_core.types.LeadTime(value: timedelta)[source]#
Bases:
PydanticStringPrimitiveRepresents a lead time as a timedelta.
Used for serialization and validation of lead time values. Maintains a consistent string representation for timedeltas in ISO 8601 format.
Example
Creating and using lead times
>>> from datetime import timedelta >>> lt = LeadTime(timedelta(hours=6)) >>> str(lt) 'PT6H' >>> LeadTime.from_string('PT6H').value datetime.timedelta(seconds=21600) >>> LeadTime.validate(timedelta(days=1)).value datetime.timedelta(days=1)
- Parameters:
value (
timedelta)
- __init__(value: timedelta)[source]#
Initialize a LeadTime with the given timedelta value.
- Parameters:
value (
timedelta) – The timedelta representing the lead time duration.value
- __str__() str[source]#
Converts to ISO 8601 duration string.
- Return type:
- Returns:
ISO 8601 formatted duration string.
- __repr__() str[source]#
Returns a detailed string representation for debugging.
- Return type:
- Returns:
String representation showing the class name and ISO 8601 duration string.
- classmethod from_string(s: str) Self[source]#
Creates an instance from an ISO 8601 duration string.
- Parameters:
s (
str) – ISO 8601 duration string to parse.s
- Returns:
LeadTime instance parsed from the string.
- Return type:
Self
- classmethod validate(v: Self | str | timedelta, _info: ValidationInfo | None = None) Self[source]#
Validates and converts various input types to LeadTime.
Accepts LeadTime objects, ISO 8601 duration strings, or timedelta objects.