diff --git a/docs/docs/string_formatting.md b/docs/docs/string_formatting.md index 91b95fc4..a00611e0 100644 --- a/docs/docs/string_formatting.md +++ b/docs/docs/string_formatting.md @@ -140,6 +140,7 @@ The following tokens are currently supported: | | SSSS ... | 000[0..] 001[0..] ... 998[0..] 999[0..] | | | SSSSSS | | | **AM / PM** | A | AM, PM | +| | a | am, pm | | **Timezone** | Z | -07:00, -06:00 ... +06:00, +07:00 | | | ZZ | -0700, -0600 ... +0600, +0700 | | | z | Asia/Baku, Europe/Warsaw, GMT ... | 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)