pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

String does not match format DDMMMYY

Open gitfran opened this issue 4 years ago • 2 comments

Hi,

"String does not match format DDMMMYY" this happens for example when the date is 14NOV22 or 14nov22, and it works only when the first letter of the month is in uppercase 14Nov22.

It would be greate if it works in all those cases.

Thanks!

gitfran avatar Nov 01 '22 15:11 gitfran

You should use strict=False

print(pendulum.parse("14nov22", strict=False))
2014-11-22 00:00:00+00:00

tudopropaganda avatar Apr 14 '25 19:04 tudopropaganda

The strict=False example above is not an equivalent workaround: it returns 2014-11-22, whereas DDMMMYY for 14nov22 means 2022-11-14. That fallback goes through dateutil and its date-order preferences, rather than preserving the supplied format contract.

The current formatter has two relevant layers: _replace_tokens() builds case-sensitive month alternatives, and Locale.match_translation() performs an exact-value lookup. Making only the regex case-insensitive would leave the second layer unmatched; normalize the captured month and lookup candidates consistently as well. Keeping this scoped to month tokens also avoids accidentally changing escaped literal matching.

Suggested regression table: 14Nov22, 14NOV22, and 14nov22 with DDMMMYY, all asserting year 2022, month 11, day 14; repeat with DDMMMYYYY and reject an unknown month. Asserting the full date catches the misleading fallback result.

I maintain DateParser Kotlin; its MIT English month grammar is a case-normalization reference, not a Python dependency. I haven't run Pendulum's tests.

Alox1d avatar Oct 15 '26 12:10 Alox1d