Skip to content

Ignore quoted literals when selecting date and time fields - #1341

Open
Str0k wants to merge 1 commit into
python-babel:masterfrom
Str0k:fix/ignore-quoted-date-format-fields
Open

Ignore quoted literals when selecting date and time fields#1341
Str0k wants to merge 1 commit into
python-babel:masterfrom
Str0k:fix/ignore-quoted-date-format-fields

Conversation

@Str0k

@Str0k Str0k commented Sep 12, 2026

Copy link
Copy Markdown

parse_date and parse_time currently search the raw format pattern for field letters. Letters inside quoted text can therefore change the inferred field order or enable an AM/PM adjustment even though the pattern has no day-period field.

For example, parse_date('2024 day 04 01', format="yyyy 'day' MM dd") returns January 4 instead of April 1. Likewise, parse_time('at 03:30 pm', format="'at' HH:mm 'pm'") returns 15:30 instead of 03:30.

Use the existing pattern tokenizer to consider only field tokens when selecting date/time components. This also respects escaped apostrophes within quoted text. The existing numeric extraction and supported field set are unchanged.

Validation on Windows with Python 3.12 and the project's CLDR 48.2 import:

  • Six regression cases fail before the fix and pass after it: quoted date fields, escaped apostrophes, quoted minute/second fields, and a quoted day-period marker.
  • Full suite: 7,834 passed, 9 skipped, 2 expected failures.
  • Ruff lint passes for both modified files.

AI assistance: Codex helped develop the patch and regression tests. The diff and verification results are provided for maintainer review.

Co-authored-by: Codex <noreply@openai.com>
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