preheat_open.time.DateRange
- class preheat_open.time.DateRange(ranges=None, resolution=TimeResolution.RAW, start=None, end=None)
Bases:
objectRepresents a collection of SubDateRange objects.
- Parameters:
ranges (List[SubDateRange]) – A list of SubDateRange objects.
resolution (TimeResolution) – The time resolution of the DateRange.
- Examples:
>>> from datetime import datetime >>> from preheat_open.time import SubDateRange, DateRange, TimeResolution >>> sdr = SubDateRange(datetime(2023, 1, 1), datetime(2023, 1, 2)) >>> dr = DateRange([sdr], resolution=TimeResolution.DAY) >>> print(dr) DateRange(2023-01-01--2023-01-02, continuous, resolution=TimeResolution.DAY)
- __init__(ranges=None, resolution=TimeResolution.RAW, start=None, end=None)
Initialize a DateRange object.
- Parameters:
ranges (List[SubDateRange]) – A list of SubDateRange objects.
resolution (TimeResolution) – The time resolution of the DateRange.
start (Optional[datetime]) – Optional start datetime.
end (Optional[datetime]) – Optional end datetime.
Methods
__init__([ranges, resolution, start, end])Initialize a DateRange object.
astimezone([tz])Convert the DateRange to a new timezone.
gaps()Calculate the gaps between consecutive DateRanges.
intersection(other)Return the intersection of two DateRange objects.
iter_ranges(freq)Iterate over the ranges of the DateRange.
Remove overlapping ranges by merging them.
Convert the DateRange to a pandas DateRange object.
union()Return a DateRange covering the entire period, including gaps.
Attributes
Checks if the DateRange is empty.
Returns the start date of the DateRange.
Returns the end date of the DateRange.
Checks if the DateRange is segmented.
Checks if the DateRange is timezone-aware.
- astimezone(tz=None)
Convert the DateRange to a new timezone.
- Parameters:
tz (Optional[tzinfo]) – The new timezone.
- Return type:
- property empty: bool
Checks if the DateRange is empty.
- Returns:
True if empty, False otherwise.
- Return type:
bool
- gaps()
Calculate the gaps between consecutive DateRanges.
- Returns:
A new DateRange object representing the gaps between ranges.
- Return type:
- intersection(other)
Return the intersection of two DateRange objects.
- iter_ranges(freq)
Iterate over the ranges of the DateRange.
- Returns:
A generator yielding tuples of start and end datetimes.
- Return type:
Generator[tuple[datetime, datetime], None, None]
- property lstart: datetime | None
Returns the start date of the DateRange.
- Returns:
The start date.
- Return type:
Optional[datetime]
- remove_overlaps()
Remove overlapping ranges by merging them.
- property rend: datetime | None
Returns the end date of the DateRange.
- Returns:
The end date.
- Return type:
Optional[datetime]
- property segmented: bool
Checks if the DateRange is segmented.
- Returns:
True if segmented, False otherwise.
- Return type:
bool
- to_pandas_date_range()
Convert the DateRange to a pandas DateRange object.
- Returns:
A pandas DateRange object.
- Return type:
pandas.core.indexes.datetimes.DatetimeIndex
- property tz_aware: bool
Checks if the DateRange is timezone-aware.
- Returns:
True if timezone-aware, False otherwise.
- Return type:
bool