Skip to content

Conversation

@nickita-khylkouski
Copy link
Contributor

Summary

Fixes #99

English text patterns (month names, weekday names, AM/PM) now explicitly use Locale.ENGLISH when creating DateTimeFormatter instances. This ensures consistent parsing behavior regardless of the JVM's default locale.

Problem

In non-English locales (e.g., French, German), DateTimeFormats.formatOf("Jan 11 2011") would fail because DateTimeFormatter.ofPattern() uses the system default locale. In French locale, "Jan" would be interpreted as "janv." (French abbreviation), causing parse failure.

Solution

Extended inferLocaleIfNeeded() to detect English locale tokens (month abbreviations, full month names, weekday abbreviations, full weekday names, AM/PM markers) and explicitly set Locale.ENGLISH for those patterns.

Changes

  • Extended inferLocaleIfNeeded() to handle English locale tokens (lines 325-335)
  • Updated LOCAL_DATE_FORMATTERS initialization to use mapKeyValue() for signature access (line 195)
  • Added inferLocaleIfNeeded() call to placeholder pattern path (line 303)

nickita-khylkouski and others added 4 commits January 21, 2026 18:00
Tests were failing in non-US locales (GB, FR, etc.) due to:
- AM/PM parsing differences (US: "AM" vs UK: "am")
- Timezone abbreviation ambiguity (PST resolves differently)
- Date formatting variations across locales

Added JUnit @rule to ensure all tests run with US locale and UTC
timezone. The rule saves the original locale/timezone before each
test and restores them afterward in a finally block.

This approach follows the standard JUnit TestRule pattern and ensures
test isolation without affecting production code.

Fixes google#93
English text patterns (month names, weekday names, AM/PM) now explicitly
use Locale.ENGLISH when creating DateTimeFormatter instances. This ensures
consistent parsing behavior regardless of the JVM's default locale.

Fixes google#99
Copy link
Collaborator

@fluentfuture fluentfuture left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@fluentfuture fluentfuture merged commit 89952b5 into google:master Jan 22, 2026
1 of 5 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.

DateTimeFormats.formatOf() fails in non-English locales for English month names

2 participants