Internationalization and localization tools


Locale-Sensitive JavaScript Method

Date.UTC(year, month, date);
Date.UTC(year, month, date, hours);
Date.UTC(year, month, date, hours, minutes);
Date.UTC(year, month, date, hours, minutes, seconds);
Date.UTC(year, month ,date, hours, minutes, seconds, milliseconds);

Internationalization (I18n) Method Overview

The UTC static method returns a time value that is the number of milliseconds since January 1, 1970 00:00:00 UTC. The entered values are based on UTC (Universal Time Zone).

Click here (w3schools) and here (MDN) for additional details.

I18n Issues

Whether or not calling UTC is an i18n issue is dependent on how it is being used in the application. Some possible i18n issues are:

  • UTC time zone is being used rather than either the system's local time zone or the application's time zone.
  • The date value parameter is assumed to be the start of the week rather than using the locale to determine the start of the week.
  • A 2-digit year is being passed into the method which won't support dates after the year 1999.

Suggested Replacement

To address the first i18n issue, call one of the Date constructors, which use the system's local time zone (or a passed in time zone) to create a date object. You can then call getTime to get the milliseconds time value.

When formatting the date for display, call one of the locale-sensitive date methods, which support formatting based on locale as well as setting the time zone:

toLocaleDateString
toLocaleString
toLocaleTimeString

To support the weekday starting value based on locale, you will need to either use a 3rd party javascript calendar library or retrieve the value from a locale-sensitive resource file.

Be sure to pass in a 4-digit rather than 2-digit year; otherwise 1900 will be added to the value and dates after the year 1999 will not be supported.


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

 

Lingoport internationalization and localization services and software