From c6338d085fc0fafe492c2203e14464473251ee06 Mon Sep 17 00:00:00 2001 From: Andreas Stenius Date: Fri, 21 Aug 2026 14:36:53 +0200 Subject: [PATCH 1/2] add failing test --- tests/test_util.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 370e36cf5..2043e1772 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -46,6 +46,10 @@ def test_convert_python_to_java_datetime_format_with_single_quote() -> None: assert strftime_to_simple_date_format("%Y'%m'%d") == "yyyy''MM''dd" +def test_convert_python_to_java_datetime_format_with_utc_offset_with_colon() -> None: + assert strftime_to_simple_date_format("%:z") == "XXX" + + class Args(NamedTuple): """ Named tuple to hold the arguments passed to a function. From ba5eb8f87e2681f36c81ee929c9d96b50fd48779 Mon Sep 17 00:00:00 2001 From: Andreas Stenius Date: Fri, 21 Aug 2026 14:53:29 +0200 Subject: [PATCH 2/2] fix: properly handle three character date time format codes. --- src/pact/_util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pact/_util.py b/src/pact/_util.py index 56b29cc69..6dda413f5 100644 --- a/src/pact/_util.py +++ b/src/pact/_util.py @@ -109,8 +109,6 @@ def strftime_to_simple_date_format(python_format: str) -> str: Returns: The equivalent Java SimpleDateFormat format string. """ - # Each Python format code is exactly two characters long, so we can - # safely iterate through the string. idx = 0 result: str = "" escaped = False @@ -121,13 +119,17 @@ def strftime_to_simple_date_format(python_format: str) -> str: if c == "%": c = python_format[idx] + # Increment another time to skip the second character of the + # Python format code. + idx += 1 + if c == ":": + # This is a three character code. + c += python_format[idx] + idx += 1 if escaped: result += "'" escaped = False result += format_code_to_java_format(c) - # Increment another time to skip the second character of the - # Python format code. - idx += 1 continue if c == "'":