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

Method __new__

src/pendulum/duration.py:71–126  ·  view source on GitHub ↗
(
        cls,
        days: float = 0,
        seconds: float = 0,
        microseconds: float = 0,
        milliseconds: float = 0,
        minutes: float = 0,
        hours: float = 0,
        weeks: float = 0,
        years: float = 0,
        months: float = 0,
    )

Source from the content-addressed store, hash-verified

69 _invert = None
70
71 def __new__(
72 cls,
73 days: float = 0,
74 seconds: float = 0,
75 microseconds: float = 0,
76 milliseconds: float = 0,
77 minutes: float = 0,
78 hours: float = 0,
79 weeks: float = 0,
80 years: float = 0,
81 months: float = 0,
82 ) -> Self:
83 if not isinstance(years, int) or not isinstance(months, int):
84 raise ValueError("Float year and months are not supported")
85
86 self = timedelta.__new__(
87 cls,
88 days + years * 365 + months * 30,
89 seconds,
90 microseconds,
91 milliseconds,
92 minutes,
93 hours,
94 weeks,
95 )
96
97 # Intuitive normalization
98 total = self.total_seconds() - (years * 365 + months * 30) * SECONDS_PER_DAY
99 self._total = total
100
101 m = 1
102 if total < 0:
103 m = -1
104
105 self._microseconds = round(total % m * 1e6)
106 self._seconds = abs(int(total)) % SECONDS_PER_DAY * m
107
108 _days = abs(int(total)) // SECONDS_PER_DAY * m
109 self._days = _days
110 self._remaining_days = abs(_days) % 7 * m
111 self._weeks = abs(_days) // 7 * m
112 self._months = months
113 self._years = years
114
115 self._signature = { # type: ignore[attr-defined]
116 "years": years,
117 "months": months,
118 "weeks": weeks,
119 "days": days,
120 "hours": hours,
121 "minutes": minutes,
122 "seconds": seconds,
123 "microseconds": microseconds + milliseconds * 1000,
124 }
125
126 return self
127
128 def total_minutes(self) -> float:

Callers 1

__new__Method · 0.45

Calls 1

total_secondsMethod · 0.95

Tested by

no test coverage detected