From 8fa1382beb4f64e95befd32df304484c82cd5e2a Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 4 Feb 2019 22:09:51 +0000 Subject: [PATCH] change ms/s watershed for datetime parsing (#385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * change ms/s watershed for datetime parsing * more tests for ms, μs and ns * fix formatting * uprev --- HISTORY.rst | 3 ++- pydantic/datetime_parse.py | 4 +++- pydantic/version.py | 2 +- tests/test_datetime_parse.py | 12 ++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2e8a6d6..eb32fc4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,7 +3,7 @@ History ------- -v0.19.0 (unreleased) +v0.19.0 (2019-02-04) .................... * Support ``Callable`` type hint, fix #279 by @proofit404 * Fix schema for fields with ``validator`` decorator, fix #375 by @tiangolo @@ -12,6 +12,7 @@ v0.19.0 (unreleased) * Deprecated ``ignore_extra`` and ``allow_extra`` Config fields in favor of ``extra``, #352 by @liiight * Add type annotations to all functions, test fully with mypy, #373 by @samuelcolvin * fix for 'missing' error with ``validate_all`` or ``validate_always``, #381 by @samuelcolvin +* Change the second/millisecond watershed for date/datetime parsing to ``2e10``, #385 by @samuelcolvin v0.18.2 (2019-01-22) .................... diff --git a/pydantic/datetime_parse.py b/pydantic/datetime_parse.py index 3e66aae..ccf0f83 100644 --- a/pydantic/datetime_parse.py +++ b/pydantic/datetime_parse.py @@ -58,7 +58,9 @@ iso8601_duration_re = re.compile( ) EPOCH = datetime(1970, 1, 1) -MS_WATERSHED = int(1e11) # if greater than this, the number is in ms (in seconds this is 3rd March 5138) +# if greater than this, the number is in ms, if less than or equal it's in seconds +# (in seconds this is 11th October 2603, in ms it's 20th August 1970) +MS_WATERSHED = int(2e10) StrIntFloat = Union[str, int, float] diff --git a/pydantic/version.py b/pydantic/version.py index fc0f7ca..fd9f9a7 100644 --- a/pydantic/version.py +++ b/pydantic/version.py @@ -2,4 +2,4 @@ from distutils.version import StrictVersion __all__ = ['VERSION'] -VERSION = StrictVersion('0.18.2') +VERSION = StrictVersion('0.19.0') diff --git a/tests/test_datetime_parse.py b/tests/test_datetime_parse.py index b9fa7d0..4e85a75 100644 --- a/tests/test_datetime_parse.py +++ b/tests/test_datetime_parse.py @@ -34,6 +34,12 @@ def create_tz(minutes): # Invalid inputs ('x20120423', errors.DateError), ('2012-04-56', errors.DateError), + (19_999_999_999, date(2603, 10, 11)), # just before watershed + (20_000_000_001, date(1970, 8, 20)), # just after watershed + (1_549_316_052, date(2019, 2, 4)), # nowish in s + (1_549_316_052_104, date(2019, 2, 4)), # nowish in ms + (1_549_316_052_104_324, date(2019, 2, 4)), # nowish in μs + (1_549_316_052_104_324_096, date(2019, 2, 4)), # nowish in ns ], ) def test_date_parsing(value, result): @@ -90,6 +96,12 @@ def test_time_parsing(value, result): # Invalid inputs ('x20120423091500', errors.DateTimeError), ('2012-04-56T09:15:90', errors.DateTimeError), + (19_999_999_999, datetime(2603, 10, 11, 11, 33, 19, tzinfo=timezone.utc)), # just before watershed + (20_000_000_001, datetime(1970, 8, 20, 11, 33, 20, 1000, tzinfo=timezone.utc)), # just after watershed + (1_549_316_052, datetime(2019, 2, 4, 21, 34, 12, 0, tzinfo=timezone.utc)), # nowish in s + (1_549_316_052_104, datetime(2019, 2, 4, 21, 34, 12, 104_000, tzinfo=timezone.utc)), # nowish in ms + (1_549_316_052_104_324, datetime(2019, 2, 4, 21, 34, 12, 104_324, tzinfo=timezone.utc)), # nowish in μs + (1_549_316_052_104_324_096, datetime(2019, 2, 4, 21, 34, 12, 104_324, tzinfo=timezone.utc)), # nowish in ns ], ) def test_datetime_parsing(value, result):