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
6 changes: 4 additions & 2 deletions src/pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,16 @@ def _format_localizable_token(
first_day = cast("int", locale.get("translations.week_data.first_day"))

return locale.ordinalize((dt.day_of_week % 7 - first_day) % 7 + 1)
elif token == "A":
elif token in ["A", "a"]:
key = "translations.day_periods"
if dt.hour >= 12:
key += ".pm"
else:
key += ".am"

return cast("str", locale.get(key))
meridiem = cast("str", locale.get(key))

return meridiem.lower() if token == "a" else meridiem
else:
return token

Expand Down
7 changes: 7 additions & 0 deletions tests/formatting/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ def test_am_pm():
assert f.format(d.set(hour=11), "A") == "AM"


def test_lowercase_am_pm():
f = Formatter()
d = pendulum.datetime(2016, 8, 28, 23)
assert f.format(d, "a") == "pm"
assert f.format(d.set(hour=11), "a") == "am"


def test_hour():
f = Formatter()
d = pendulum.datetime(2016, 8, 28, 7)
Expand Down