Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-28073

Android: DateTimeFormat mishandles some combinations of settings on Android 8

    Details

    • Story Points:
      3

      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:

      1. Build and run the below code on Android 8.
      2. Notice an error gets logged: Failed to generate 'best' date pattern.
      3. 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.)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Gary Mathews
                Tester:
                Samir Mohammed
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration