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

Method __new__

src/pendulum/interval.py:41–117  ·  view source on GitHub ↗
(cls, start: _T, end: _T, absolute: bool = False)

Source from the content-addressed store, hash-verified

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,
94 fold=end.fold,
95 ),
96 )
97 elif isinstance(end, pendulum.Date):
98 _end = cast("_T", date(end.year, end.month, end.day))

Callers

nothing calls this directly

Calls 5

datetimeFunction · 0.85
dateFunction · 0.85
utcoffsetMethod · 0.80
replaceMethod · 0.45
total_secondsMethod · 0.45

Tested by

no test coverage detected