From 2c2a8d03c8706cc24f1f45be945e7c4cf139aa43 Mon Sep 17 00:00:00 2001 From: Frank Tobia Date: Wed, 2 Jan 2019 14:03:34 -0500 Subject: [PATCH] Fix issue #168: intervals greater than one day were incorrect. --- maya/core.py | 4 +++- tests/test_maya_interval.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/maya/core.py b/maya/core.py index cdf018b..e66bbd3 100644 --- a/maya/core.py +++ b/maya/core.py @@ -806,4 +806,6 @@ def intervals(start, end, interval): while current_timestamp.epoch < end.epoch: yield current_timestamp - current_timestamp = current_timestamp.add(seconds=interval.seconds) + current_timestamp = current_timestamp.add( + seconds=interval.total_seconds() + ) diff --git a/tests/test_maya_interval.py b/tests/test_maya_interval.py index 1d040a4..1e1362b 100755 --- a/tests/test_maya_interval.py +++ b/tests/test_maya_interval.py @@ -570,3 +570,16 @@ def test_interval_from_iso8601_duration(): assert interval.start == s assert interval.end == e + + +def test_issue_168_regression(): + start = maya.now() + end = start.add(weeks=1) + gen = maya.intervals(start=start, end=end, interval=60 * 60 * 24) + # Since the bug causes the generator to never end, first sanity + # check that two results are not the same. + assert next(gen) != next(gen) + assert ( + len(list(maya.intervals(start=start, end=end, interval=60 * 60 * 24))) + == 7 + )