Skip to content

Commit

Permalink
Merge pull request #22 from ambitioninc/develop
Browse files Browse the repository at this point in the history
fixed a bug when a recurrence crosses a day light savings time boundary
  • Loading branch information
wesleykendall committed Apr 1, 2015
2 parents 72dcd28 + 3487a46 commit 9865fef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion localized_recurrence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def utc_of_next_schedule(self, current_time):
can be called without side-effect.
"""
local_time = fleming.convert_to_tz(current_time, self.timezone)
local_scheduled_time = _replace_with_offset(local_time, self.offset, self.interval)
local_scheduled_time = fleming.fleming.dst_normalize(
_replace_with_offset(local_time, self.offset, self.interval))
utc_scheduled_time = fleming.convert_to_tz(local_scheduled_time, pytz.utc, return_naive=True)
if utc_scheduled_time <= current_time:
additional_time = {
Expand All @@ -166,6 +167,7 @@ def utc_of_next_schedule(self, current_time):
}
utc_scheduled_time = fleming.add_timedelta(
utc_scheduled_time, additional_time[self.interval], within_tz=self.timezone)

return utc_scheduled_time


Expand Down
7 changes: 7 additions & 0 deletions localized_recurrence/tests/models_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ def test_basic_works(self):
schedule_out = self.lr_day.utc_of_next_schedule(current_time)
self.assertEqual(schedule_out, expected_next_schedule)

def test_dst_cross_monthly(self):
"""The case when a monthly recurrence goes past daylight savings time"""
self.lr_month.offset = timedelta(hours=0)
self.lr_month.previous_scheduled = datetime(2015, 2, 1, 6)
scheduled_out = self.lr_month.utc_of_next_schedule(datetime(2015, 3, 31))
self.assertEqual(scheduled_out, datetime(2015, 4, 1, 5))

def test_before_midnight(self):
"""The case when the scheduled and current time cross midnight.
Expand Down
2 changes: 1 addition & 1 deletion localized_recurrence/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.1'
__version__ = '1.0.2'

0 comments on commit 9865fef

Please sign in to comment.