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 == "'": 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.