Skip to content

Commit

Permalink
Move base date in test_time 10 years back to fix Y2k38 issues
Browse files Browse the repository at this point in the history
Change the frozen date in test_time from 2020 to 2010, in order to fix
overflow when processing "27 years from now" date on systems with 32-bit
time_t.  Since the date is arbitrary and frozen anyway, this seems to be
the cleanest solution to keep the test suite working portably.

Fixes #176
  • Loading branch information
mgorny committed Feb 29, 2024
1 parent 066923b commit 14d9ba9
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions tests/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ONE_DAY = 24 * ONE_HOUR
ONE_YEAR = 365.25 * ONE_DAY

FROZEN_DATE = "2020-02-02"
FROZEN_DATE = "2010-02-02"
with freeze_time(FROZEN_DATE):
NOW = dt.datetime.now()
NOW_UTC = dt.datetime.now(tz=dt.timezone.utc)
Expand Down Expand Up @@ -248,31 +248,31 @@ def test_naturalday(test_args: list[typing.Any], expected: str) -> None:
("Not a date at all.", "Not a date at all."),
(VALUE_ERROR_TEST, str(VALUE_ERROR_TEST)),
(OVERFLOW_ERROR_TEST, str(OVERFLOW_ERROR_TEST)),
(dt.date(2019, 2, 2), "Feb 02 2019"),
(dt.date(2019, 3, 2), "Mar 02 2019"),
(dt.date(2019, 4, 2), "Apr 02 2019"),
(dt.date(2019, 5, 2), "May 02 2019"),
(dt.date(2019, 6, 2), "Jun 02 2019"),
(dt.date(2019, 7, 2), "Jul 02 2019"),
(dt.date(2019, 8, 2), "Aug 02 2019"),
(dt.date(2019, 9, 2), "Sep 02 2019"),
(dt.date(2019, 10, 2), "Oct 02"),
(dt.date(2019, 11, 2), "Nov 02"),
(dt.date(2019, 12, 2), "Dec 02"),
(dt.date(2020, 1, 2), "Jan 02"),
(dt.date(2020, 2, 2), "today"),
(dt.date(2020, 3, 2), "Mar 02"),
(dt.date(2020, 4, 2), "Apr 02"),
(dt.date(2020, 5, 2), "May 02"),
(dt.date(2020, 6, 2), "Jun 02"),
(dt.date(2020, 7, 2), "Jul 02"),
(dt.date(2020, 8, 2), "Aug 02 2020"),
(dt.date(2020, 9, 2), "Sep 02 2020"),
(dt.date(2020, 10, 2), "Oct 02 2020"),
(dt.date(2020, 11, 2), "Nov 02 2020"),
(dt.date(2020, 12, 2), "Dec 02 2020"),
(dt.date(2021, 1, 2), "Jan 02 2021"),
(dt.date(2021, 2, 2), "Feb 02 2021"),
(dt.date(2009, 2, 2), "Feb 02 2009"),
(dt.date(2009, 3, 2), "Mar 02 2009"),
(dt.date(2009, 4, 2), "Apr 02 2009"),
(dt.date(2009, 5, 2), "May 02 2009"),
(dt.date(2009, 6, 2), "Jun 02 2009"),
(dt.date(2009, 7, 2), "Jul 02 2009"),
(dt.date(2009, 8, 2), "Aug 02 2009"),
(dt.date(2009, 9, 2), "Sep 02 2009"),
(dt.date(2009, 10, 2), "Oct 02"),
(dt.date(2009, 11, 2), "Nov 02"),
(dt.date(2009, 12, 2), "Dec 02"),
(dt.date(2010, 1, 2), "Jan 02"),
(dt.date(2010, 2, 2), "today"),
(dt.date(2010, 3, 2), "Mar 02"),
(dt.date(2010, 4, 2), "Apr 02"),
(dt.date(2010, 5, 2), "May 02"),
(dt.date(2010, 6, 2), "Jun 02"),
(dt.date(2010, 7, 2), "Jul 02"),
(dt.date(2010, 8, 2), "Aug 02 2010"),
(dt.date(2010, 9, 2), "Sep 02 2010"),
(dt.date(2010, 10, 2), "Oct 02 2010"),
(dt.date(2010, 11, 2), "Nov 02 2010"),
(dt.date(2010, 12, 2), "Dec 02 2010"),
(dt.date(2011, 1, 2), "Jan 02 2011"),
(dt.date(2011, 2, 2), "Feb 02 2011"),
],
)
def test_naturaldate(test_input: dt.date, expected: str) -> None:
Expand Down

0 comments on commit 14d9ba9

Please sign in to comment.