Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f64e676

Browse files
committed
Allow timedelta to be converted to a ordinalf
1 parent f53be2f commit f64e676

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/matplotlib/dates.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,19 @@ def _get_rc_timezone():
207207

208208
def _to_ordinalf(dt):
209209
"""
210-
Convert :mod:`datetime` or :mod:`date` to the Gregorian date as UTC float
211-
days, preserving hours, minutes, seconds and microseconds. Return value
212-
is a :func:`float`.
210+
Convert :mod:`datetime`, :mod:`date` or :mod:`timedelta` to the Gregorian
211+
date as UTC float days, preserving hours, minutes, seconds and
212+
microseconds. Return value is a :func:`float`.
213213
"""
214214
# Convert to UTC
215215
tzi = getattr(dt, 'tzinfo', None)
216216
if tzi is not None:
217217
dt = dt.astimezone(UTC)
218218
tzi = UTC
219219

220+
if isinstance(dt, datetime.timedelta):
221+
return dt.total_seconds() / SEC_PER_DAY
222+
220223
base = float(dt.toordinal())
221224

222225
# If it's sufficiently datetime-like, it will have a `date()` method

0 commit comments

Comments
 (0)