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

Skip to content

Commit 72ef748

Browse files
committed
Fix timezone problem, clarify docstring for timezones.
Signed-off-by: Paul G <[email protected]>
1 parent 0a5fbc6 commit 72ef748

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/matplotlib/dates.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _get_rc_timezone():
208208

209209
def _to_ordinalf(dt):
210210
"""
211-
Convert :mod:`datetime` or :mod:`date` to the Gregorian date as UTC float
211+
Convert :mod:`datetime` or :mod:`date` to the Gregorian date as UTC float
212212
days, preserving hours, minutes, seconds and microseconds. Return value
213213
is a :func:`float`.
214214
"""
@@ -226,7 +226,7 @@ def _to_ordinalf(dt):
226226
midnight_time = datetime.time(0, 0, 0, tzinfo=dt.tzinfo)
227227

228228
rdt = datetime.datetime.combine(cdate, midnight_time)
229-
td_remainder = (dt-rdt).total_seconds()
229+
td_remainder = (dt - rdt).total_seconds()
230230

231231
base = float(dt.toordinal())
232232
if td_remainder > 0:
@@ -243,15 +243,21 @@ def _from_ordinalf(x, tz=None):
243243
"""
244244
Convert Gregorian float of the date, preserving hours, minutes,
245245
seconds and microseconds. Return value is a :class:`datetime`.
246+
247+
The input date `x` is a float in ordinal days at UTC, and the output will
248+
be the specified :class:`datetime` object corresponding to that time in
249+
timezone `tz`, or if `tz` is `None`, in the timezone specified in
250+
`rcParams['timezone']`.
246251
"""
247252
if tz is None:
248253
tz = _get_rc_timezone()
254+
249255
ix = int(x)
250-
dt = datetime.datetime.fromordinal(ix)
256+
dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
257+
251258
remainder = float(x) - ix
252259

253260
dt += datetime.timedelta(seconds=remainder * SEC_PER_DAY)
254-
dt = dt.astimezone(tz)
255261

256262
return dt
257263

0 commit comments

Comments
 (0)