Interval¶
The Interval class represents time ranges between two datetime points.
            carbonic.core.interval.Interval
  
      dataclass
  
¶
    Represents a time interval with start and end points.
Intervals are half-open: [start, end) - inclusive start, exclusive end. Supports both Date and DateTime intervals with comprehensive operations.
Examples:
Create intervals¶
meeting = Interval(start=DateTime(2024, 1, 15, 9, 0), end=DateTime(2024, 1, 15, 10, 30)) vacation = Interval(start=Date(2024, 7, 1), end=Date(2024, 7, 15))
Operations¶
meeting.contains(DateTime(2024, 1, 15, 9, 30)) # True meeting.overlaps(lunch_interval) # True/False meeting.intersection(lunch_interval) # Overlapping part meeting.union(lunch_interval) # Combined intervals meeting.duration() # Duration object
Functions¶
duration ¶
Get the Duration of this interval.
Returns:
| Type | Description | 
|---|---|
| Duration | Duration object representing the time span | 
is_empty ¶
Check if this interval is empty (zero duration).
Returns:
| Type | Description | 
|---|---|
| bool | True if start == end, False otherwise | 
contains ¶
overlaps ¶
Check if this interval overlaps with another interval.
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| other | Interval | Another Interval to check | required | 
Returns:
| Type | Description | 
|---|---|
| bool | True if intervals overlap, False otherwise |