Locale-Sensitive JavaScript Method
date.setHours(hours);
date.setHours(hours, minutes);
date.setHours(hours, minutes, seconds);
date.setHours(hours, minutes, seconds, milliseconds);
Internationalization (I18n) Method Overview
The setHours method sets the number of hours (0-23) for the date object, based on the system's local time zone, and returns the number of
milliseconds between the date object and midnight January 1 1970 UTC. If minutes, seconds,
or milliseconds are missing, getMinutes() , getSeconds() or getMilliseconds() will be used.
Click here (w3schools) and
here (MDN) for additional details.
I18n Issues
Whether or not calling setHours is an i18n issue is dependent on how it is being used in the application.
One possible issue is:
- The system's local time zone is being used rather than either UTC or the application's time zone. It is usually recommended that all
stored dates be in UTC time zone so that they can be retrieved and displayed based on the application's time zone.
Suggested Replacement
To address the i18n issue, call setUTCHours to use UTC time zone rather than local time zone.
Then, when displaying the date, call one of the locale-sensitive date methods, which support setting the time zone as well as using the locale to
format the date/time:
toLocaleDateString
toLocaleString
toLocaleTimeString
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
|