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

Skip to content

Commit ba623a7

Browse files
committed
Fix problem with inconsistent time zones. This now also fixes Issue #3896.
Signed-off-by: Paul G <[email protected]>
1 parent 4b0d94b commit ba623a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/matplotlib/dates.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ def _to_ordinalf(dt):
215215
if delta is not None:
216216
dt -= delta
217217

218-
base = dt.toordinal()
219-
td_remainder = (dt-datetime.datetime.fromordinal(base)).total_seconds()
218+
# Get a datetime object at midnight in the same time zone as dt.
219+
cdate = dt.date()
220+
midnight_time = datetime.time(0, 0, 0, tzinfo=dt.tzinfo)
220221

221-
base = float(base)
222+
rdt = datetime.datetime.combine(cdate, midnight_time)
223+
td_remainder = (dt-rdt).total_seconds()
224+
225+
base = float(dt.toordinal())
222226
if td_remainder > 0:
223-
base ++ td_remainder / SEC_PER_DAY
227+
base += td_remainder / SEC_PER_DAY
224228

225229
return base
226230

0 commit comments

Comments
 (0)