kennethreitz / maya

Datetimes for Humans™
MIT License
3.41k stars 199 forks source link

Problem computing time ranges using ".intervals()" #168

Closed amotl closed 5 years ago

amotl commented 5 years ago

Hi there,

while the promised

print('\n'.join(map(lambda x: x.rfc3339(), \
  maya.intervals(start=maya.now(), end=maya.now().add(days=1), interval=60*60))))

seems to work as expected, we had problems when computing time ranges with different parameters.

While, when attempting to compute time ranges of one week into the future, using an

interval of 23 hours

print('\n'.join(map(lambda x: x.rfc3339(), \
  maya.intervals(start=maya.now(), end=maya.now().add(weeks=1), interval=60*60*23))))

still seems to work fine, running the computation with an

interval of 24 hours

print('\n'.join(map(lambda x: x.rfc3339(), \
  maya.intervals(start=maya.now(), end=maya.now().add(weeks=1), interval=60*60*24))))

runs into an endless loop. On the other hand, using

25 hours as an interval

in fact uses an interval of 1 hour:

print('\n'.join(map(lambda x: x.rfc3339(), \
  maya.intervals(start=maya.now(), end=maya.now().add(weeks=1), interval=60*60*25))))

Maybe you or @timofurrer could have a look at this?

Last but not least: Thanks for conceiving and maintaining this fine Python package. Have a Merry Christmas or other holiday of your choice!

With kind regards, Andreas.

amotl commented 5 years ago

In the meanwhile, we settled for the rrule feature from the dateutil package as @moin18 suggested at Iterator for continuous datetimes. Thanks, Moinuddin!

ftobia commented 5 years ago

I just ran into this. The problem seems to be that the implementation doesn't correctly account for a timedelta's seconds. I have a proposed fix here: https://github.com/kennethreitz/maya/pull/169

timofurrer commented 5 years ago

Fixed by @ftobia ! Thank you very much! :tada: