@@ -213,24 +213,22 @@ def _to_ordinalf(dt):
213
213
is a :func:`float`.
214
214
"""
215
215
216
- if isinstance (dt , datetime .date ):
217
- return float (datetime .datetime .toordinal (dt ))
218
-
219
216
if hasattr (dt , 'tzinfo' ) and dt .tzinfo is not None :
220
217
delta = dt .tzinfo .utcoffset (dt )
221
218
if delta is not None :
222
219
dt -= delta
223
220
224
- # Get a datetime object at midnight in the same time zone as dt.
225
- cdate = dt .date ()
226
- midnight_time = datetime .time (0 , 0 , 0 , tzinfo = dt .tzinfo )
221
+ base = float (dt .toordinal ())
222
+ if isinstance (dt , datetime .datetime ):
223
+ # Get a datetime object at midnight in the same time zone as dt.
224
+ cdate = dt .date ()
225
+ midnight_time = datetime .time (0 , 0 , 0 , tzinfo = dt .tzinfo )
227
226
228
- rdt = datetime .datetime .combine (cdate , midnight_time )
229
- td_remainder = (dt - rdt ).total_seconds ()
227
+ rdt = datetime .datetime .combine (cdate , midnight_time )
228
+ td_remainder = (dt - rdt ).total_seconds ()
230
229
231
- base = float (dt .toordinal ())
232
- if td_remainder > 0 :
233
- base += td_remainder / SEC_PER_DAY
230
+ if td_remainder > 0 :
231
+ base += td_remainder / SEC_PER_DAY
234
232
235
233
return base
236
234
@@ -382,10 +380,9 @@ def drange(dstart, dend, delta):
382
380
*dend* are :class:`datetime` instances. *delta* is a
383
381
:class:`datetime.timedelta` instance.
384
382
"""
385
- step = (delta .days + delta .seconds / SEC_PER_DAY +
386
- delta .microseconds / MUSECONDS_PER_DAY )
387
383
f1 = _to_ordinalf (dstart )
388
384
f2 = _to_ordinalf (dend )
385
+ step = delta .total_seconds () / SEC_PER_DAY
389
386
390
387
# calculate the difference between dend and dstart in times of delta
391
388
num = int (np .ceil ((f2 - f1 ) / step ))
0 commit comments