Internationalization and localization tools


Locale-Sensitive JavaScript Method

date.setYear(year);

Internationalization (I18n) Method Overview

The setYear method sets the year for the date object, based on the system's local time zone.

For example:

var date = new Date();
date.setYear(95); // will add 1900 to numbers between 0-99, inclusive
var result1 = date.getFullYear();
date.setYear(2014); // will just use number as full year otherwise
var result2 = date.getFullYear();

Method returns:

result1: 1995
result2: 2014


Click here for additional details.

Note: setYear is no longer supported by Web Standards and should be replaced with setFullYear or setUTCFullYear.

I18n Issues

setYear should be replaced by calling either setFullYear or setUTCFullYear. And then, whether or not the replacement method is an i18n issue is dependent on how it is used in the application. Two possible i18n issues are:

  • The system's local time zone is being used rather than either UTC or the application's time zone.
  • The returned number is being used to format a date string for display, rather than using the locale to determine the preferred date order and display.

Suggested Replacement

To address the first i18n issue, call setUTCFullYear to use UTC time zone rather than local time zone. To set the time zone, call one of the locale-sensitive date methods:

toLocaleDateString
toLocaleString
toLocaleTimeString

These locale-sensitive date methods also address the second i18n issue: that of formatting dates based on locale.


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