MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / Interval

Class Interval

src/pendulum/interval.py:36–420  ·  view source on GitHub ↗

An interval of time between two datetimes.

Source from the content-addressed store, hash-verified

34
35
36class Interval(Duration, Generic[_T]):
37 """
38 An interval of time between two datetimes.
39 """
40
41 def __new__(cls, start: _T, end: _T, absolute: bool = False) -> Self:
42 if (isinstance(start, datetime) and not isinstance(end, datetime)) or (
43 not isinstance(start, datetime) and isinstance(end, datetime)
44 ):
45 raise ValueError(
46 "Both start and end of an Interval must have the same type"
47 )
48
49 if (
50 isinstance(start, datetime)
51 and isinstance(end, datetime)
52 and (
53 (start.tzinfo is None and end.tzinfo is not None)
54 or (start.tzinfo is not None and end.tzinfo is None)
55 )
56 ):
57 raise TypeError("can't compare offset-naive and offset-aware datetimes")
58
59 if absolute and start > end:
60 end, start = start, end
61
62 _start = start
63 _end = end
64 if isinstance(start, pendulum.DateTime):
65 _start = cast(
66 "_T",
67 datetime(
68 start.year,
69 start.month,
70 start.day,
71 start.hour,
72 start.minute,
73 start.second,
74 start.microsecond,
75 tzinfo=start.tzinfo,
76 fold=start.fold,
77 ),
78 )
79 elif isinstance(start, pendulum.Date):
80 _start = cast("_T", date(start.year, start.month, start.day))
81
82 if isinstance(end, pendulum.DateTime):
83 _end = cast(
84 "_T",
85 datetime(
86 end.year,
87 end.month,
88 end.day,
89 end.hour,
90 end.minute,
91 end.second,
92 end.microsecond,
93 tzinfo=end.tzinfo,

Callers 7

intervalFunction · 0.90
diffMethod · 0.90
diffMethod · 0.90
test_rangeFunction · 0.90
test_range_no_overflowFunction · 0.90
test_range_invertedFunction · 0.90
test_iterFunction · 0.90

Calls

no outgoing calls

Tested by 4

test_rangeFunction · 0.72
test_range_no_overflowFunction · 0.72
test_range_invertedFunction · 0.72
test_iterFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…