Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/pact/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 == "'":
Expand Down
4 changes: 4 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down