@@ -30,7 +30,7 @@ def __init__(self, left: T, right: T) -> None:
3030 raise ValueError (f"Expected right to be a datetime or cftime.datetime, got { type (right )} ." )
3131 if left >= right :
3232 raise ValueError (f"Expected left to be strictly less than right, got left={ left } and right={ right } ." )
33- if not _is_compatible (left , right ):
33+ if not is_compatible (left , right ):
3434 raise ValueError (f"Expected left and right to be compatible, got left={ left } and right={ right } ." )
3535
3636 self .left = left
@@ -52,16 +52,16 @@ def __ne__(self, other: object) -> bool:
5252
5353 def intersection (self , other : TimeInterval ) -> TimeInterval | None :
5454 """Return the intersection of two time intervals. Returns None if there is no overlap."""
55- try :
56- start = max ( self . left , other . left )
57- end = min ( self . right , other . right )
58- except Exception as e :
59- raise ValueError ( "TimeIntervals are not compatible." ) from e
55+ if not is_compatible ( self . left , other . left ) :
56+ raise ValueError ( "TimeIntervals are not compatible." )
57+
58+ start = max ( self . left , other . left )
59+ end = min ( self . right , other . right )
6060
6161 return TimeInterval (start , end ) if start <= end else None
6262
6363
64- def _is_compatible (t1 : datetime | cftime .datetime , t2 : datetime | cftime .datetime ) -> bool :
64+ def is_compatible (t1 : datetime | cftime .datetime , t2 : datetime | cftime .datetime ) -> bool :
6565 """Checks whether two (cftime.)datetime objects are compatible."""
6666 try :
6767 t1 - t2
0 commit comments