Skip to content

Use Locale.ENGLISH when parsing dates in Converter.DATE#426

Merged
garydgregory merged 2 commits into
apache:masterfrom
rootvector2:converter-date-locale
Jun 28, 2026
Merged

Use Locale.ENGLISH when parsing dates in Converter.DATE#426
garydgregory merged 2 commits into
apache:masterfrom
rootvector2:converter-date-locale

Conversation

@rootvector2

Copy link
Copy Markdown
Contributor

Converter.DATE parses with a default-locale SimpleDateFormat, but its documented input (the output of Date.toString()) always uses English month and day names, so a Date-typed option throws ParseException under any non-English default locale; pinning Locale.ENGLISH keeps the documented round-trip stable, which is also why testCreateDate already needed a @DefaultLocale pin.

@garydgregory garydgregory changed the title use Locale.ENGLISH when parsing dates in Converter.DATE Use Locale.ENGLISH when parsing dates in Converter.DATE Jun 27, 2026

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rootvector2
How do you avoid breaking existing apps? Try to parse it twice? Rebase on git master and see the new test:
org.apache.commons.cli.ConverterTests.testDateLocaleDe()

@rootvector2 rootvector2 force-pushed the converter-date-locale branch from 1dfda70 to 88803df Compare June 28, 2026 14:50
@rootvector2

Copy link
Copy Markdown
Contributor Author

Rebased on master. You're right that pinning Locale.ENGLISH outright would break testDateLocaleDe and any app passing a default-locale string, so I went with the parse-twice route: Converter.DATE now parses with the default locale first and only falls back to Locale.ENGLISH when that throws. Anything that parses today hits the exact same first parse, so existing behavior is unchanged; the fallback only covers the Date.toString() output, which is always English regardless of locale. Added testDateLocaleDeEnglishInput to lock that path under a de default. Both it and your testDateLocaleDe pass.

@garydgregory garydgregory merged commit f3ba9c9 into apache:master Jun 28, 2026
10 checks passed
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.

2 participants