Skip to content

Commit f40b4a0

Browse files
Yasser Ancoghlan
authored andcommitted
bpo-36138: Clarify docs about converting datetime.timedelta to scalars. (GH-12137)
Be explicit that timedelta division converts an overall duration to the interval units given by the denominator.
1 parent d2fdd1f commit f40b4a0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Doc/library/datetime.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,9 @@ Supported operations:
254254
| | rounded to the nearest multiple of |
255255
| | timedelta.resolution using round-half-to-even.|
256256
+--------------------------------+-----------------------------------------------+
257-
| ``f = t2 / t3`` | Division (3) of *t2* by *t3*. Returns a |
258-
| | :class:`float` object. |
257+
| ``f = t2 / t3`` | Division (3) of overall duration *t2* by |
258+
| | interval unit *t3*. Returns a :class:`float` |
259+
| | object. |
259260
+--------------------------------+-----------------------------------------------+
260261
| ``t1 = t2 / f or t1 = t2 / i`` | Delta divided by a float or an int. The result|
261262
| | is rounded to the nearest multiple of |
@@ -351,7 +352,8 @@ Instance methods:
351352
.. method:: timedelta.total_seconds()
352353

353354
Return the total number of seconds contained in the duration. Equivalent to
354-
``td / timedelta(seconds=1)``.
355+
``td / timedelta(seconds=1)``. For interval units other than seconds, use the
356+
division form directly (e.g. ``td / timedelta(microseconds=1)``).
355357

356358
Note that for very large time intervals (greater than 270 years on
357359
most platforms) this method will lose microsecond accuracy.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve documentation about converting datetime.timedelta to scalars.

0 commit comments

Comments
 (0)