[TIMOB-28278] Android: localized date/time format should default to numeric
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Unresolved |
Affected Version/s | Release 9.1.0 |
Fix Version/s | Release 9.3.1 |
Components | Android |
Labels | Intl, android, date, datetime, localization, parity |
Reporter | Hans Knöchel |
Assignee | Joshua Quick |
Created | 2020-12-09T08:57:11.000+0000 |
Updated | 2020-12-18T19:31:31.000+0000 |
Description
Run the following code on your web-browser, iOS and Android:
new Date(2020, 11, 9).toLocaleDateString('en');
The results are:
* Web: 12/9/2020
* iOS: 12/9/2020
* Android: 12/9/{color:red}20{color} <-- YY instead of YYYY
It seems like Android uses the wrong year format.
This is not a bug. It's using the default pattern coming from the current locale. This just means the current locale is set up to use a 2 digit year. I've seen different locales provide 4 digit years on my devices as well. A great example of this is a Japanese "ja-JP" locale which does an ISO format of "yyyy/mm/dd" and requires a 4 digit year. Basically it's supposed to use the pattern the system is configured for. https://stackoverflow.com/questions/22719346/tolocaledatestring-is-not-returning-dd-mm-yyyy-format If you want a consistent format, then you will need to do this...
I don't understand. We do pass the locale to the
toLocaleDateString
function and all other platforms return the format correctly - on the same environment / locale.Currently, the
toLocaleDateString()
andtoLocaleTimeString()
methods use the "short" date/time patterns defined by the system. https://github.com/appcelerator/titanium_mobile/blob/master/common/Resources/ti.internal/extensions/js/Date.js But after having a look at Mozilla's docs [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString), the date/time components are supposed to be set to "numeric" if undefined. I can't find where this is documented in the ECMA spec (they say it's "implementation defined"), but I can see now this appears to be the expected behavior. Here's the quote from Mozilla's docs... bq. The default value for each date-time component property is undefined, but if the weekday, year, month, day properties are all undefined, then year, month, and day are assumed to be "numeric". So, you're right. We should change it to default to "numeric".Thanks for the insight, Josh! Also, thanks for the workaround - we will patch the SDK and are ready to go then :-)
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12332
FR Passed. Waiting for Jenkins build.
merged to master, backport PR merged to 9_3_X for 9.3.1 target