Locale-Sensitive JavaScript Method
Date.parse(dateString);
Internationalization (I18n) Method Overview
This static method parses a date string, returning the number of milliseconds since January 1, 1970, 00:00:00 UTC.
UTC stands for Universal Coordinated Time and is the primary time standard for the world; it can be used interchangeably with Greenwich Mean Time (GMT),
though UTC supersedes GMT.
The dateString parameter must be in a one of these two formats:
-
RFC 2822 / IETF date syntax
The time zone can be specified as either a continental US time zone abbreviation or a time zone offset from UTC.
For example:
"Tue, 04 Sep 2014 08:20:00 MST"
"Tue, 04 Sep 2014 08:20:00 -0700"
When no time zone is specified, the system's time zone is assumed.
-
ISO format 8601
The time zone must be specified as an offset from UTC, or Z for UTC.
For example, the following correspond to the same time value:
"2014-09-04T08:20:30-07:00" which is September 4, 2014 8:20:30 am, US Mountain Standard Time
"2014-09-04T15:20:30Z" which is September 4, 2014 3:20:30 pm, UTC
When no time zone is specified, UTC time zone is assumed.
Click here (w3schools) and
here (MDN) for additional method details.
I18n Issues
JavaScript dates are often based on the system's time zone, rather than an application's specified time zone. In addition, the dateString
parameter must be in one of two formats: a U.S. centric format or the ISO 8601 format, rather than allowing a user to enter a date based on their preferred date/time
format. You will need to look at each Date.parse call to ensure that it is performing as expected
once your application supports multiple locales and a time zone other than your system time zone.
Suggested Replacement
If you must use JavaScript to parse user-entered dates, then we recommend that they enter dates in the ISO 8601 format, which is understood by all locales.
In addition, make sure that the dateString parameter includes the time zone.
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
|