From 665666d6f4213da8db57ebb480947b7caf1fe382 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 17 Dec 2023 15:36:26 +0100 Subject: Merging upstream version 3.0.0. Signed-off-by: Daniel Baumann --- tests/datetime/test_from_format.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'tests/datetime/test_from_format.py') diff --git a/tests/datetime/test_from_format.py b/tests/datetime/test_from_format.py index 10c4a23..184c0a0 100644 --- a/tests/datetime/test_from_format.py +++ b/tests/datetime/test_from_format.py @@ -81,9 +81,8 @@ def test_from_format_with_invalid_padded_day(): ("12/02/1999", "DD/MM/YYYY", "1999-02-12T00:00:00+00:00", None), ("12_02_1999", "DD_MM_YYYY", "1999-02-12T00:00:00+00:00", None), ("12:02:1999", "DD:MM:YYYY", "1999-02-12T00:00:00+00:00", None), - ("2-2-99", "D-M-YY", "2099-02-02T00:00:00+00:00", None), - ("2-2-99", "D-M-YY", "1999-02-02T00:00:00+00:00", "1990-01-01"), - ("99", "YY", "2099-01-01T00:00:00+00:00", None), + ("2-2-99", "D-M-YY", "1999-02-02T00:00:00+00:00", None), + ("99", "YY", "1999-01-01T00:00:00+00:00", None), ("300-1999", "DDD-YYYY", "1999-10-27T00:00:00+00:00", None), ("12-02-1999 2:45:10", "DD-MM-YYYY h:m:s", "1999-02-12T02:45:10+00:00", None), ("12-02-1999 12:45:10", "DD-MM-YYYY h:m:s", "1999-02-12T12:45:10+00:00", None), @@ -100,7 +99,8 @@ def test_from_format_with_invalid_padded_day(): ("Monday", "dddd", "2018-01-29T00:00:00+00:00", "2018-02-02"), ("Mon", "ddd", "2018-01-29T00:00:00+00:00", "2018-02-02"), ("Mo", "dd", "2018-01-29T00:00:00+00:00", "2018-02-02"), - ("0", "d", "2018-02-04T00:00:00+00:00", "2018-02-02"), + ("0", "d", "2018-01-29T00:00:00+00:00", "2018-02-02"), + ("6", "d", "2018-02-04T00:00:00+00:00", "2018-02-02"), ("1", "E", "2018-01-29T00:00:00+00:00", "2018-02-02"), ("March", "MMMM", "2018-03-01T00:00:00+00:00", "2018-02-02"), ("Mar", "MMM", "2018-03-01T00:00:00+00:00", "2018-02-02"), @@ -150,10 +150,7 @@ def test_from_format_with_invalid_padded_day(): ], ) def test_from_format(text, fmt, expected, now): - if now is None: - now = pendulum.datetime(2015, 11, 12) - else: - now = pendulum.parse(now) + now = pendulum.datetime(2015, 11, 12) if now is None else pendulum.parse(now) with pendulum.travel_to(now, freeze=True): assert pendulum.from_format(text, fmt).isoformat() == expected @@ -201,3 +198,25 @@ def test_strptime(): assert_datetime(d, 1975, 5, 21, 22, 32, 11) assert isinstance(d, pendulum.DateTime) assert d.timezone_name == "UTC" + + +def test_from_format_2_digit_year(): + """ + Complies with open group spec for 2 digit years + https://pubs.opengroup.org/onlinepubs/9699919799/ + + "If century is not specified, then values in the range [69,99] shall + refer to years 1969 to 1999 inclusive, and values in the + range [00,68] shall refer to years 2000 to 2068 inclusive." + """ + d = pendulum.from_format("00", "YY") + assert d.year == 2000 + + d = pendulum.from_format("68", "YY") + assert d.year == 2068 + + d = pendulum.from_format("69", "YY") + assert d.year == 1969 + + d = pendulum.from_format("99", "YY") + assert d.year == 1999 -- cgit v1.2.3