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

Class Duration

src/pendulum/duration.py:46–471  ·  view source on GitHub ↗

Replacement for the standard timedelta class. Provides several improvements over the base class.

Source from the content-addressed store, hash-verified

44
45
46class Duration(timedelta):
47 """
48 Replacement for the standard timedelta class.
49
50 Provides several improvements over the base class.
51 """
52
53 _total: float = 0
54 _years: int = 0
55 _months: int = 0
56 _weeks: int = 0
57 _days: int = 0
58 _remaining_days: int = 0
59 _seconds: int = 0
60 _microseconds: int = 0
61
62 _y = None
63 _m = None
64 _w = None
65 _d = None
66 _h = None
67 _i = None
68 _s = None
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

Callers 5

durationFunction · 0.90
time.pyFile · 0.90
as_durationMethod · 0.90
_parse_iso8601_durationFunction · 0.90
duration.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…