Locale-Sensitive JavaScript Constructor
new Intl.DateTimeFormat();
new Intl.DateTimeFormat(locales);
new Intl.DateTimeFormat(locales, options);
Internationalization (I18n) Method Overview
The Intl.DateTimeFormat constructor returns an object that can then be used to format a date based on locale. If no parameters are passed to the
constructor, then the default locale is used. Fallback is support with the locales parameters, which may be an array of locales.
options can be used to override the locale's default formatting settings.
Click here (MDN) for additional details.
I18n Issues
Whether or not calling Intl.DateTimeFormat is an i18n issue is dependent on how it is being used in the application.
Two possible issues are:
- The formatted date needs to be locale-independent; i.e always the same, regardless the locale.
- A version of the constructor is being called that does not include the locales parameter and so dates may not be formatted based on the
application's locale.
Suggested Replacement
Don't use the Intl.DateTimeFormat object to format dates that should be locale-independent. Instead, call the
Microsoft .NET JavaScript Extension format method or toString
to format dates independent of locale. You could also use the options argument to override all locale format settings, ensuring the same format, regardless
the locale.
Otherwise, be sure that the locale is set properly and then pass it into the constructor.
Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can
use Globalyzer's Ignore Comment
functionality to ensure that it isn't picked up in a subsequent scan.
Locale-Sensitive JavaScript Methods
|