Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28073] Android: DateTimeFormat mishandles some combinations of settings on Android 8

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-08-11T11:24:17.000+0000
Affected Version/sRelease 9.1.0
Fix Version/sRelease 9.1.0
ComponentsAndroid
LabelsDateTimeFormat, Intl, android, date
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-08-07T03:06:24.000+0000
Updated2021-01-18T08:20:37.000+0000

Description

*Summary:* If you set up 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.)

Comments

  1. Joshua Quick 2020-08-07

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11874
  2. Christopher Williams 2020-08-07

    merged to master, auto-backported and merged to 9_1_X and 9_3_X
  3. Samir Mohammed 2020-08-11

    *Closing ticket*. Improvement verified in SDK version 9.1.0.v20200810120239, 9.2.0.v20200810085310 and 9.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*
       MacOS Big Sur: 11.0 Beta
       Xcode: 12.0 Beta 
       Java Version: 1.8.0_242
       Android NDK: 21.3.6528147
       Node.js: 12.18.1
       ""NPM":"5.0.0","CLI":"8.1.0-master.5""
       API29 Pixel XL emulator
       

JSON Source