preheat_open.time.SubDateRange

class preheat_open.time.SubDateRange(start=None, end=None)

Bases: object

Represents a range of dates with a start and an end.

Parameters:
  • start (Optional[datetime]) – The starting date of the range.

  • end (Optional[datetime]) – The ending date of the range.

Examples:
>>> from datetime import datetime
>>> sdr = SubDateRange(datetime(2023, 1, 1), datetime(2023, 1, 2))
>>> print(sdr)
[2023-01-01 00:00:00, 2023-01-02 00:00:00]
>>> print(sdr.tz_aware)
False
__init__(start=None, end=None)

Initialize a SubDateRange object. :type start: Optional[datetime] :param start: The starting date of the range. :type start: Optional[datetime] :type end: Optional[datetime] :param end: The ending date of the range. :type end: Optional[datetime]

Methods

__init__([start, end])

Initialize a SubDateRange object.

check_start_end()

Ensure start is before end and they are not equal.

merge(other)

Merge this range with another, assuming they overlap.

overlap(other)

Returns the overlapping portion of two SubDateRange objects.

Attributes

tz_aware

Checks if the SubDateRange is timezone-aware.

check_start_end()

Ensure start is before end and they are not equal.

Raises:

TypeError – If the start date is after the end date or both are equal.

merge(other)

Merge this range with another, assuming they overlap.

Parameters:

other (SubDateRange) – The other SubDateRange to merge with.

Returns:

A new merged SubDateRange.

Return type:

SubDateRange

Raises:

ValueError – If the ranges do not overlap.

overlap(other)

Returns the overlapping portion of two SubDateRange objects. If there’s no overlap, returns None.

Parameters:

other (SubDateRange) – Another SubDateRange object.

Returns:

The overlapping SubDateRange or None if no overlap.

Return type:

Optional[SubDateRange]

property tz_aware: bool

Checks if the SubDateRange is timezone-aware.

Returns:

True if timezone-aware, False otherwise.

Return type:

bool