myusuf3 / delorean

Delorean: Time Travel Made Easy
http://delorean.rtfd.org/
MIT License
1.84k stars 128 forks source link

Error handling fractional seconds? #75

Open liavkoren opened 8 years ago

liavkoren commented 8 years ago

It's possible I'm missing something here, but it seems like Delorean doesn't handle fractional seconds correctly in the next_second/last_second methods:

In [115]: dt
Out[115]: datetime.datetime(2015, 1, 1, 0, 0)

In [116]: d = Delorean(dt, timezone='utc')

In [117]: d.next_second(0.5).datetime
Out[117]: datetime.datetime(2015, 1, 1, 0, 0, tzinfo=<UTC>)

In [118]: _.microsecond
Out[118]: 0

In [119]: dt + relativedelta(seconds=0.5)
Out[119]: datetime.datetime(2015, 1, 1, 0, 0, 0, 500000)

Fractional days do seem to work:

In [124]: d.next_day(0.7390)
Out[124]: Delorean(datetime=2015-01-01 17:44:09.600000+00:00, timezone=utc)

BTW, really enjoying the package so far, it's made the code I've been writing an order of magnitude better.

liavkoren commented 8 years ago

Also seems to be an issue with next_hour.