Pass Locale.US to Clock date parsing and formatting in Dates.java#3988
Open
apexpdl wants to merge 1 commit into
Open
Pass Locale.US to Clock date parsing and formatting in Dates.java#3988apexpdl wants to merge 1 commit into
apexpdl wants to merge 1 commit into
Conversation
Dates.java created SimpleDateFormat instances without a Locale in
three places: tryParseDate (backs Clock.MakeInstant), FormatDateTime,
and FormatDate. On devices set to a Thai locale, SimpleDateFormat
resolves against the Buddhist calendar, so MakeInstant("06/10/2026")
reads 2026 as a Buddhist Era year and returns Gregorian year 1483.
Apps that parse stored or hardcoded date strings silently get
instants ~543 years in the past. Formatting has the mirror problem.
This passes Locale.US to all three, following the approach approved
and merged in mit-cml#3891 for the Chart components. The documented format
strings fully specify component order, so the locale only pins the
calendar and digit script.
Also surfaces the underlying ParseException: tryParseDate previously
swallowed it with an empty catch, so a failed parse threw an
IllegalArgumentException with no detail. The exception now includes
the input value and the last parse error as its cause.
WeekdayName/MonthName style functions are intentionally untouched;
they use locale display names by design.
Addresses the Android half of mit-cml#3984.
Collaborator
|
Can one of the admins verify this patch? |
1 similar comment
Collaborator
|
Can one of the admins verify this patch? |
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR accomplish?
Description
Android half of #3984. The iOS half is #3989.
Dates.javacreatesSimpleDateFormatinstances without aLocalein three places:tryParseDate(which backsClock.MakeInstant),FormatDateTime, andFormatDate. On a Thai-locale device,SimpleDateFormatresolves against the Buddhist calendar, soClock.MakeInstant("06/10/2026")reads 2026 as a Buddhist Era year and returns Gregorian year 1483. Any app that parses a saved or hardcoded date string silently gets an instant about 543 years in the past. Formatting has the mirror problem, which also breaks round-trips (format a date, store it, parse it later).This PR passes
Locale.USto all three, the same approach approved and merged in #3891 for the Chart components. The documented format strings (MM/dd/yyyy,HH:mm, etc.) fully specify component order, so the locale only pins the calendar and digit script. It does not change date layout for anyone.It also fixes a debuggability problem in the same function:
tryParseDateswallowedParseExceptionwith an empty catch, so a failed parse threwIllegalArgumentExceptionwith no detail. The exception now includes the input value and carries the last parse error as its cause.WeekdayName/MonthNamestyle functions are intentionally untouched. They use locale display names by design and should keep doing so.Testing Guidelines
Clock.MakeInstant("06/10/2026")thenClock.Year(...)on the result.1483. After this PR:2026.Clock.FormatDatean instant, parse it back withClock.MakeInstant, confirm the same instant on any locale.Addresses the Android portion of #3984.
Context for the changes
This is Android Companion runtime code, so it targets the
ucrbranch per the contributing guidelines.If your code changes how something works on the device (i.e., it affects the companion):
I have made no changes that affect the companion
I branched from
ucrMy pull request has
ucras the baseFor all other changes:
I have made no changes that affect the master branch
I branched from
masterMy pull request has
masteras the baseGeneral items:
ant testspasses on my machine