diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-07-13 18:23:51 +0200 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2019-07-13 18:23:51 +0200 |
commit | 3e3eff9ee639a60052a3fb4ae2e6955d2f85ae92 (patch) | |
tree | 718219bb58386a213c8da891cf34b3d73503b67a | |
parent | 300f7962036bc9ba35946f83cd33690992447a60 (diff) |
Dates in the remote future could belong to a different release
-rwxr-xr-x | debdate | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -15,6 +15,7 @@ import argparse import csv import datetime from dateutil import relativedelta, parser +import math import unittest RELEASES = [ @@ -35,6 +36,7 @@ RELEASES = [ (datetime.date(1996, 6, 17), 'buzz'), ] MSG = "Today is day {dody} of year {yodr} of the {release}" +FUTURE_MSG = "Today could be day {dody} of year {yodr} of the {release}" ERR_MSG = "Today is {isodate} of the Debianless Age" @@ -71,6 +73,13 @@ class DebDate: def get_release(self, day): data = {} + today = datetime.date.today() + if day > today: + # This is just a fuzzy way to decide whether a date is + # likely to be after a future release. + data['certain'] = math.exp((today - day).days / 365.25 ) + else: + data['certain'] = 1 for r in self.releases: epoch = r[0] data['release'] = r[1] @@ -112,6 +121,7 @@ class TestDebDate(unittest.TestCase): self.assertEqual(data['dody'], 10) self.assertEqual(data['yodr'], 1) self.assertEqual(data['release'], r[1]) + self.assertEqual(data['certain'], 1) def testSecondYearRelease(self): for debdate in self.debdates: @@ -121,6 +131,7 @@ class TestDebDate(unittest.TestCase): self.assertEqual(data['dody'], 227) self.assertEqual(data['yodr'], 2) self.assertEqual(data['release'], r[1]) + self.assertEqual(data['certain'], 1) def testJanuarySecondYearRelease(self): for debdate in self.debdates: @@ -130,6 +141,7 @@ class TestDebDate(unittest.TestCase): self.assertEqual(data['dody'], 1) self.assertEqual(data['yodr'], 2) self.assertEqual(data['release'], r[1]) + self.assertEqual(data['certain'], 1) def testPastLatestRelease(self): for debdate in self.debdates: @@ -140,6 +152,7 @@ class TestDebDate(unittest.TestCase): # release, so we do not check it self.assertEqual(data['yodr'], 6) self.assertEqual(data['release'], r[1]) + self.assertLess(data['certain'], 1) def testBeforeBeginningOfTime(self): for debdate in self.debdates: @@ -194,7 +207,11 @@ class Command: except OutsideTimeError: print(ERR_MSG.format(isodate=date.strftime("%Y-%m-%d"))) else: - print(MSG.format(**data)) + if data['certain'] > 0.14: + print(MSG.format(**data)) + else: + print(FUTURE_MSG.format(**data)) + def main(self): self.setup_parser() |