Skip to content

Commit 33ec185

Browse files
committed
Add docstrings to Duration properties and in_*/total_* methods
1 parent 7149d52 commit 33ec185

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

‎src/pendulum/duration.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,31 @@ def __new__(
126126
return self
127127

128128
def total_minutes(self) -> float:
129+
"""
130+
The total length of the duration in minutes, as a float.
131+
Years count as 365 days and months as 30 days.
132+
"""
129133
return self.total_seconds() / SECONDS_PER_MINUTE
130134

131135
def total_hours(self) -> float:
136+
"""
137+
The total length of the duration in hours, as a float.
138+
Years count as 365 days and months as 30 days.
139+
"""
132140
return self.total_seconds() / SECONDS_PER_HOUR
133141

134142
def total_days(self) -> float:
143+
"""
144+
The total length of the duration in days, as a float.
145+
Years count as 365 days and months as 30 days.
146+
"""
135147
return self.total_seconds() / SECONDS_PER_DAY
136148

137149
def total_weeks(self) -> float:
150+
"""
151+
The total length of the duration in weeks, as a float.
152+
Years count as 365 days and months as 30 days.
153+
"""
138154
return self.total_days() / 7
139155

140156
if PYPY:
@@ -160,14 +176,24 @@ def total_seconds(self) -> float:
160176

161177
@property
162178
def years(self) -> int:
179+
"""
180+
The years component the duration was created with.
181+
"""
163182
return self._years
164183

165184
@property
166185
def months(self) -> int:
186+
"""
187+
The months component the duration was created with.
188+
"""
167189
return self._months
168190

169191
@property
170192
def weeks(self) -> int:
193+
"""
194+
The number of whole weeks in the days part of the duration.
195+
Years and months are not included: see in_weeks() for the total.
196+
"""
171197
return self._weeks
172198

173199
if PYPY:
@@ -178,10 +204,16 @@ def days(self) -> int:
178204

179205
@property
180206
def remaining_days(self) -> int:
207+
"""
208+
The days left over after whole weeks are taken out of the days part.
209+
"""
181210
return self._remaining_days
182211

183212
@property
184213
def hours(self) -> int:
214+
"""
215+
The hours component of the time part (negative if the duration is).
216+
"""
185217
if self._h is None:
186218
seconds = self._seconds
187219
self._h = 0
@@ -192,6 +224,9 @@ def hours(self) -> int:
192224

193225
@property
194226
def minutes(self) -> int:
227+
"""
228+
The minutes component of the time part (negative if the duration is).
229+
"""
195230
if self._i is None:
196231
seconds = self._seconds
197232
self._i = 0
@@ -202,10 +237,17 @@ def minutes(self) -> int:
202237

203238
@property
204239
def seconds(self) -> int:
240+
"""
241+
The time part of the duration in seconds (negative if the duration is).
242+
Whole days are not included: see in_seconds() for the total.
243+
"""
205244
return self._seconds
206245

207246
@property
208247
def remaining_seconds(self) -> int:
248+
"""
249+
The seconds component of the time part (negative if the duration is).
250+
"""
209251
if self._s is None:
210252
self._s = self._seconds
211253
self._s = abs(self._s) % 60 * self._sign(self._s)
@@ -214,28 +256,49 @@ def remaining_seconds(self) -> int:
214256

215257
@property
216258
def microseconds(self) -> int:
259+
"""
260+
The microseconds component of the duration.
261+
"""
217262
return self._microseconds
218263

219264
@property
220265
def invert(self) -> bool:
266+
"""
267+
True if the duration is negative.
268+
"""
221269
if self._invert is None:
222270
self._invert = self.total_seconds() < 0
223271

224272
return self._invert
225273

226274
def in_weeks(self) -> int:
275+
"""
276+
The total length of the duration in whole weeks (rounded towards zero).
277+
"""
227278
return int(self.total_weeks())
228279

229280
def in_days(self) -> int:
281+
"""
282+
The total length of the duration in whole days (rounded towards zero).
283+
"""
230284
return int(self.total_days())
231285

232286
def in_hours(self) -> int:
287+
"""
288+
The total length of the duration in whole hours (rounded towards zero).
289+
"""
233290
return int(self.total_hours())
234291

235292
def in_minutes(self) -> int:
293+
"""
294+
The total length of the duration in whole minutes (rounded towards zero).
295+
"""
236296
return int(self.total_minutes())
237297

238298
def in_seconds(self) -> int:
299+
"""
300+
The total length of the duration in whole seconds (rounded towards zero).
301+
"""
239302
return int(self.total_seconds())
240303

241304
def in_words(self, locale: str | None = None, separator: str = " ") -> str:

0 commit comments

Comments
 (0)