From 8fc7815189ed324779a8844d690499ccc6558114 Mon Sep 17 00:00:00 2001 From: Chason Chaffin Date: Fri, 19 Apr 2019 16:19:15 +0900 Subject: [PATCH] Fixing bug in gametime module Previously, gametime used the length of the current year and current month to calculate the future date in the real_seconds_until function. This caused a small bug when passing over a leap day from a year without a leap day. This change uses the datetime module to just increment the year or month, sidestepping the issue. --- evennia/utils/gametime.py | 9 +++++---- evennia/utils/tests/test_gametime.py | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/evennia/utils/gametime.py b/evennia/utils/gametime.py index c3cc0ac416..f964c4b053 100644 --- a/evennia/utils/gametime.py +++ b/evennia/utils/gametime.py @@ -189,12 +189,13 @@ def real_seconds_until(sec=None, min=None, hour=None, if projected <= current: # We increase one unit of time depending on parameters - days_in_month = monthrange(s_year, s_month)[1] - days_in_year = sum(monthrange(s_year, m + 1)[1] for m in range(12)) if month is not None: - projected += timedelta(days=days_in_year) + projected = projected.replace(year=s_year+1) elif day is not None: - projected += timedelta(days=days_in_month) + try: + projected = projected.replace(month=s_month+1) + except ValueError: + projected = projected.replace(month=1) elif hour is not None: projected += timedelta(days=1) elif min is not None: diff --git a/evennia/utils/tests/test_gametime.py b/evennia/utils/tests/test_gametime.py index cc2a759c18..7b11f4b043 100644 --- a/evennia/utils/tests/test_gametime.py +++ b/evennia/utils/tests/test_gametime.py @@ -78,7 +78,6 @@ class TestGametime(TestCase): self.assertAlmostEqual(gametime.real_seconds_until(day=17), 501120) self.assertAlmostEqual(gametime.real_seconds_until(month=1), 4752000) - @unittest.expectedFailure def test_real_seconds_until_leap_year(self): self.assertAlmostEqual(gametime.real_seconds_until(month=3), 5788800)