[TIMOB-28073] Android: DateTimeFormat mishandles some combinations of settings on Android 8
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-08-11T11:24:17.000+0000 |
Affected Version/s | Release 9.1.0 |
Fix Version/s | Release 9.1.0 |
Components | Android |
Labels | DateTimeFormat, Intl, android, date |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-08-07T03:06:24.000+0000 |
Updated | 2021-01-18T08:20:37.000+0000 |
Description
*Summary:*
If you set up Notice an error gets logged:
Notice displayed date is
Intl.DateTimeFormat
to use 12-hour time and fractional digits on Android 8.x, then it will log an error and output a different format. This is not an issue on older or new Android OS versions.
*Steps to reproduce:*
Build and run the below code on Android 8.
Notice an error gets logged: Failed to generate 'best' date pattern.
Notice displayed date is "3/31/20 8:15 PM"
which doesn't match format settings.
var date = new Date(Date.UTC(2020, 2, 31, 20, 15, 30, 123));
var formatter = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
fractionalSecondDigits: 3,
hour12: true,
timeZone: 'UTC'
});
var window = Ti.UI.createWindow();
window.add(Ti.UI.createLabel({ text: formatter.format(date) }));
window.open();
*Result:*
The following error gets logged...
[ERROR] DateTimeFormatProxy: (main) [37,37] Failed to generate 'best' date pattern.
[ERROR] DateTimeFormatProxy: java.lang.IllegalArgumentException: Illegal pattern character 'b'
[ERROR] DateTimeFormatProxy: at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:870)
[ERROR] DateTimeFormatProxy: at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:684)
[ERROR] DateTimeFormatProxy: at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:623)
*Expected Result:*
No error should be logged.
The displayed date should be...
03/31/2020, 8:15:30.123 PM
*Cause:*
This is a bug on Google's end. It is adding invalid format character 'b'
for the AM/PM component when it should be using format character 'a'
instead. This used to be a bug in Oracle's JDK as well...
https://bugs.openjdk.java.net/browse/JDK-8209047
Titanium was correctly catching the exception and falling-back to use a basic date/time format, but unfortunately that means it won't match the given format settings. (Having the fallback is still a good thing.)
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11874
merged to master, auto-backported and merged to 9_1_X and 9_3_X
*Closing ticket*. Improvement verified in SDK version
9.1.0.v20200810120239
,9.2.0.v20200810085310
and9.3.0.v20200810090511
. Tested using the test case mentioned above. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11874 *Test Environment*