File tree 1 file changed +9
-2
lines changed 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,12 @@ def _from_ordinalf(x, tz=None):
257
257
258
258
dt += datetime .timedelta (seconds = remainder * SEC_PER_DAY )
259
259
260
+ # Compensate for rounding errors
261
+ if dt .microsecond < 10 :
262
+ dt = dt .replace (microsecond = 0 )
263
+ elif dt .microsecond > 999990 :
264
+ dt += datetime .timedelta (microseconds = 1e6 - dt .microsecond )
265
+
260
266
return dt
261
267
262
268
@@ -944,14 +950,15 @@ def autoscale(self):
944
950
def get_locator (self , dmin , dmax ):
945
951
'Pick the best locator based on a distance.'
946
952
delta = relativedelta (dmax , dmin )
953
+ tdelta = dmax - dmin
947
954
948
955
# take absolute difference
949
956
if dmin > dmax :
950
957
delta = - delta
951
958
952
- numYears = ( delta .years * 1.0 )
959
+ numYears = delta .years * 1.0
953
960
numMonths = (numYears * MONTHS_PER_YEAR ) + delta .months
954
- numDays = ( numMonths * DAYS_PER_MONTH ) + delta . days
961
+ numDays = tdelta . days # Avoid estimates of days/month, days/year
955
962
numHours = (numDays * HOURS_PER_DAY ) + delta .hours
956
963
numMinutes = (numHours * MIN_PER_HOUR ) + delta .minutes
957
964
numSeconds = (numMinutes * SEC_PER_MIN ) + delta .seconds
You can’t perform that action at this time.
0 commit comments