@@ -208,7 +208,7 @@ def _get_rc_timezone():
208
208
209
209
def _to_ordinalf (dt ):
210
210
"""
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
212
212
days, preserving hours, minutes, seconds and microseconds. Return value
213
213
is a :func:`float`.
214
214
"""
@@ -226,7 +226,7 @@ def _to_ordinalf(dt):
226
226
midnight_time = datetime .time (0 , 0 , 0 , tzinfo = dt .tzinfo )
227
227
228
228
rdt = datetime .datetime .combine (cdate , midnight_time )
229
- td_remainder = (dt - rdt ).total_seconds ()
229
+ td_remainder = (dt - rdt ).total_seconds ()
230
230
231
231
base = float (dt .toordinal ())
232
232
if td_remainder > 0 :
@@ -243,15 +243,21 @@ def _from_ordinalf(x, tz=None):
243
243
"""
244
244
Convert Gregorian float of the date, preserving hours, minutes,
245
245
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']`.
246
251
"""
247
252
if tz is None :
248
253
tz = _get_rc_timezone ()
254
+
249
255
ix = int (x )
250
- dt = datetime .datetime .fromordinal (ix )
256
+ dt = datetime .datetime .fromordinal (ix ).replace (tzinfo = UTC )
257
+
251
258
remainder = float (x ) - ix
252
259
253
260
dt += datetime .timedelta (seconds = remainder * SEC_PER_DAY )
254
- dt = dt .astimezone (tz )
255
261
256
262
return dt
257
263
0 commit comments