LeadTime#

class openstef_core.types.LeadTime(value: timedelta)[source]#

Bases: PydanticStringPrimitive

Represents 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:

str

Returns:

ISO 8601 formatted duration string.

__repr__() str[source]#

Returns a detailed string representation for debugging.

Return type:

str

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.

Parameters:
  • v (Union[Self, str, timedelta]) – Value to validate (LeadTime, string, or timedelta).

  • _info (ValidationInfo | None) – Additional validation info (unused).

  • v

  • _info

Returns:

Validated LeadTime instance.

Return type:

Self

__lt__(other: object) bool[source]#

Less-than comparison based on timedelta value.

Returns:

True if this LeadTime is less than the other, False otherwise.

Parameters:

other (object)

Return type:

bool

to_hours() float[source]#

Converts the lead time to total hours.

Return type:

float

Returns:

Total hours represented by the lead time.