From: Daniele Varrazzo Date: Thu, 7 Oct 2021 21:20:49 +0000 (+0200) Subject: Don't generate random timestamps BC X-Git-Tag: 3.0~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9807b501d355cfd20265b97c18f2d3302f155f2d;p=thirdparty%2Fpsycopg.git Don't generate random timestamps BC It might happen to go below datetime.datetime.min if the timezone is involved. Today the random data generator is having a field day... --- diff --git a/tests/fix_faker.py b/tests/fix_faker.py index 75f660854..63c933e73 100644 --- a/tests/fix_faker.py +++ b/tests/fix_faker.py @@ -346,13 +346,16 @@ class Faker: return self.schema_time(cls) def make_datetime(self, spec): + # Add a day because with timezone we might go BC + dtmin = dt.datetime.min + dt.timedelta(days=1) + # Comparisons might get unreliable too far in the future # https://bugs.python.org/issue45347 - # delta = dt.datetime.max - dt.datetime.min + # delta = dt.datetime.max - dtmin delta = dt.timedelta(days=3000 * 365) micros = randrange((delta.days + 1) * 24 * 60 * 60 * 1_000_000) - rv = dt.datetime.min + dt.timedelta(microseconds=micros) + rv = dtmin + dt.timedelta(microseconds=micros) if spec[1]: rv = rv.replace(tzinfo=self._make_tz(spec)) return rv