diff --git a/src/pendulum/formatting/formatter.py b/src/pendulum/formatting/formatter.py index b09977d0..51825246 100644 --- a/src/pendulum/formatting/formatter.py +++ b/src/pendulum/formatting/formatter.py @@ -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 diff --git a/tests/formatting/test_formatter.py b/tests/formatting/test_formatter.py index b83b67be..36175250 100644 --- a/tests/formatting/test_formatter.py +++ b/tests/formatting/test_formatter.py @@ -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)