Skip to content

Fix a format token returning literal instead of lowercase meridiem - #990

Closed
vedaant00 wants to merge 1 commit into
python-pendulum:masterfrom
vedaant00:fix-lowercase-a-meridiem-token
Closed

Fix a format token returning literal instead of lowercase meridiem#990
vedaant00 wants to merge 1 commit into
python-pendulum:masterfrom
vedaant00:fix-lowercase-a-meridiem-token

Conversation

@vedaant00

Copy link
Copy Markdown

What

DateTime.format("a") returns the literal string "a" instead of the lowercase am/pm marker:

import pendulum
dt = pendulum.datetime(2020, 1, 1, 14, 0, 0)
dt.format("A")  # "PM"  (correct)
dt.format("a")  # "a"   (bug — expected "pm")

Why

The a token is declared in the formatter regex and in _LOCALIZABLE_TOKENS, but _format_localizable_token has a branch for A and none for a, so a falls through to return token.

Fix

  • Add the missing a branch, mirroring A and lowercasing the localized day period (matching the existing _LOCALIZABLE_TOKENS["a"] lambda). Non-Latin locales like ja are unaffected since .lower() is a no-op there.
  • Added test_am_pm_lowercase.
  • Added the a row to the format-token docs table.

Full suite passes (1838 passed).

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

@vedaant00

Copy link
Copy Markdown
Author

Closing as a duplicate of #984, which predates this by a few weeks. Left a note there about also adding the a row to the format-token docs table (the one extra thing this PR covered).

@vedaant00 vedaant00 closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant