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

Skip to content

Commit 5af753c

Browse files
committed
Replace hard-coded conversion logic in _to_ordinalf with functions from datetime.
Signed-off-by: Paul G <[email protected]>
1 parent 390c1f4 commit 5af753c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/matplotlib/dates.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ def _get_rc_timezone():
178178
"""
179179
Time-related constants.
180180
"""
181-
EPOCH_OFFSET = 719163. # Days between 0001-01-01 and epoch, +1.
182-
JULIAN_OFFSET = 1721424.5 # Julian date at 0001-01-01
181+
EPOCH_OFFSET = float(datetime.datetime(1970, 1, 1)) # Epoch in ordinal
182+
JULIAN_OFFSET = 1721424.5 # Julian date at 0001-01-01
183183
MICROSECONDLY = SECONDLY + 1
184184
HOURS_PER_DAY = 24.
185185
MIN_PER_HOUR = 60.
@@ -214,12 +214,13 @@ def _to_ordinalf(dt):
214214
if delta is not None:
215215
dt -= delta
216216

217-
base = float(dt.toordinal())
218-
if hasattr(dt, 'hour'):
219-
base += (dt.hour / HOURS_PER_DAY + dt.minute / MINUTES_PER_DAY +
220-
dt.second / SECONDS_PER_DAY +
221-
dt.microsecond / MUSECONDS_PER_DAY
222-
)
217+
base = dt.toordinal()
218+
td_remainder = (dt-datetime.datetime.fromordinal(base)).total_seconds()
219+
220+
base = float(base)
221+
if td_remainder > 0:
222+
base ++ td_remainder / SECONDS_PER_DAY
223+
223224
return base
224225

225226

0 commit comments

Comments
 (0)