From 3fb20f12ed07946b57fbcb20b71b95d727c4c868 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 27 May 2017 12:34:21 +0200 Subject: Fix calculation of dates for the beginning of the second year --- debdate | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/debdate b/debdate index 5f10c3c..c05d297 100755 --- a/debdate +++ b/debdate @@ -82,12 +82,12 @@ class DebDate: day=day, ) ) - delta = relativedelta.relativedelta(day, epoch) - data['yodr'] = delta.years + 1 - if delta.years == 0: + if day.year == epoch.year: data['dody'] = (day - epoch).days + data['yodr'] = 1 else: data['dody'] = day.timetuple().tm_yday + data['yodr'] = day.year - epoch.year + 1 return data @@ -122,6 +122,15 @@ class TestDebDate(unittest.TestCase): self.assertEqual(data['yodr'], 2) self.assertEqual(data['release'], r[1]) + def testJanuarySecondYearRelease(self): + for debdate in self.debdates: + r = debdate.releases[-6] + d = datetime.date(r[0].year + 1, 1, 1) + data = debdate.get_release(d) + self.assertEqual(data['dody'], 1) + self.assertEqual(data['yodr'], 2) + self.assertEqual(data['release'], r[1]) + def testPastLatestRelease(self): for debdate in self.debdates: r = debdate.releases[0] -- cgit v1.2.3