Skip to content

Match month and weekday names case-insensitively in from_format - #1068

Open
tlq5l wants to merge 1 commit into
python-pendulum:masterfrom
tlq5l:fix/from-format-case-insensitive-names
Open

tlq5l wants to merge 1 commit into
python-pendulum:masterfrom
tlq5l:fix/from-format-case-insensitive-names

Conversation

@tlq5l

@tlq5l tlq5l commented Oct 21, 2026

Copy link
Copy Markdown

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code. (No docs change needed: the docs never said names were case-sensitive.)

from_format builds its regex from the locale's month and weekday names and then looks the matched text up by exact value, so 14nov22 with DDMMMYY raises String does not match format while 14Nov22 works.

This wraps the name tokens (MMMM, MMM, dddd, ddd, dd) in a scoped (?i:...) group in Formatter._replace_tokens, and makes Locale.match_translation compare lowercased values. Other tokens (T, Z, A) keep their current case rules. match_translation is only called from from_format parsing.

Fixes #668 (also covers #809).

Ran live: pendulum.from_format('14nov22','DDMMMYY') -> 2022-11-14 00:00:00+00:00 (raised ValueError before).

This branch has not been deployed

No deployments
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.

String does not match format DDMMMYY

1 participant