Skip to content

Detect day-first month-name dates with a comma before the year - #465

Merged
jzonthemtn merged 2 commits into
philterd:mainfrom
DG47:fix/day-first-comma-dates
Oct 22, 2026
Merged

jzonthemtn merged 2 commits into
philterd:mainfrom
DG47:fix/day-first-comma-dates

Conversation

@DG47

@DG47 DG47 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #462.

A day-first date with a comma before the year, such as 27 March, 1965, was not detected by the date filter, so the whole date was left in the output. Day-first dates without the comma were detected only through the optional leading day on the month-first patterns, so their spans carried MMMM yyyy (or MMMM-dd for 27-Mar-1965), which does not describe the text.

Changes:

  • DateFilter gets day-first month-name patterns, placed ahead of the month-first ones so that, for the same text, the day-first format is the one recorded on the span:
    • D Month, YYYY, format dd MMMM, yyyy
    • D<delim>Month<delim>YYYY for each of the existing delimiters (space, -, /, .), format dd MMMM yyyy, dd-MMMM-yyyy, dd/MMMM/yyyy, dd.MMMM.yyyy
    • The day is 1 to 31 with an optional leading zero and an optional ordinal (st, nd, rd, th); the month is a full or abbreviated name with an optional period; the year is any four digits, as for Month D, YYYY after Month-name dates with a two-digit day and a year before 1970 lose their year #459.
  • Tests in DateFilterTest: the forms from the issue (27 March, 1965, 27 Mar, 1965, 27th March, 1965, 3 March, 2020, and others) with onlyValidDates off and on; every day 1 to 31 with years 1900, 1950, 1969, 1970, 2025, and 2099 for the comma, space, and hyphen forms; the forms without the comma; the format on each day-first span; and that month-first dates keep their month-first formats.
  • dates.md lists the day-first forms, and RELEASE_NOTES.md has an entry.

Not changed here: like the other month-name formats, dd MMMM, yyyy uses yyyy and dd, so SHIFT and TRUNCATE_TO_YEAR still fall back to redaction for these dates. That is #461.

Testing (JDK 17):

  • mvn --batch-mode test -Dtest=DateFilterTest: before the change, filterDateDayFirstWithComma, filterDateDayFirstEveryDay, and filterDateDayFirstFormat fail; after it, Tests run: 73, Failures: 0, Errors: 0, Skipped: 0
  • mvn --batch-mode package: Tests run: 2975, Failures: 0, Errors: 0, Skipped: 0, BUILD SUCCESS

@DG47
DG47 requested a review from jzonthemtn as a code owner October 22, 2026 13:23
@jzonthemtn

Copy link
Copy Markdown
Member

Thanks @DG47!

@DG47
DG47 force-pushed the fix/day-first-comma-dates branch from 4a56d07 to 8e97439 Compare October 22, 2026 13:54
@sonarqubecloud

Copy link
Copy Markdown

@DG47

DG47 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the SonarCloud finding (regex complexity from the month-name alternation) with a java:S5843 suppression on monthName, the same way IpAddressFilter and UrlFilter handle it. The quality gate passes now.

@jzonthemtn
jzonthemtn merged commit bb3539d into philterd:main Oct 22, 2026
@jzonthemtn

Copy link
Copy Markdown
Member

Thanks @DG47!

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.

Day-first dates with a comma before the year, such as 27 March, 1965, are not detected

2 participants