Skip to content

Fix lowercase 'a' token formatting to lowercase meridiem#984

Open
vidigoat wants to merge 1 commit into
python-pendulum:masterfrom
vidigoat:fix-lowercase-meridiem-format
Open

Fix lowercase 'a' token formatting to lowercase meridiem#984
vidigoat wants to merge 1 commit into
python-pendulum:masterfrom
vidigoat:fix-lowercase-meridiem-format

Conversation

@vidigoat

@vidigoat vidigoat commented Jul 9, 2026

Copy link
Copy Markdown

The a format token returns the literal string a instead of a lowercase meridiem indicator (am/pm).

>>> import pendulum
>>> dt = pendulum.datetime(2016, 8, 28, 23)
>>> dt.format("A")
'PM'
>>> dt.format("a")   # expected 'pm'
'a'

_format_localizable_token only handles the uppercase A token, so a falls through to the default branch that returns the token unchanged. The a token is documented and registered in the token regex, and the parser side already treats it as a lowercase meridiem, so formatting and parsing were inconsistent and a value formatted with a could not be round-tripped:

>>> pendulum.from_format(dt.format("YYYY-MM-DD hh:mm a"), "YYYY-MM-DD hh:mm a")

previously failed because the formatted string contained a literal a rather than pm.

This mirrors the existing A branch and lowercases the result for the a token. Added a regression test alongside the existing test_am_pm.

The 'a' format token was returning the literal string 'a' instead of a
lowercase meridiem indicator (am/pm). Only the uppercase 'A' token was
handled in _format_localizable_token, so 'a' fell through to the default
branch that returns the token unchanged.

This also broke round-tripping: the parser already expects lowercase
am/pm for the 'a' token, but formatting produced 'a' instead.
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