Skip to content

Commit

Permalink
Fix a timezone issue in isDate()
Browse files Browse the repository at this point in the history
The validator accepts ISO 8601 dates which include "%Y-%m-%d" and
"%Y-%m-%d %H:%M". The validator makes use of Date.parse() to parse
the date before checking if the date is invalid (e.g. 2015-02-29).
The built-in Date.parse() function interprets "%Y-%m-%d" dates in
GMT but "%Y-%m-%d %H:%M" in the user's timezone. This caused the
validator to apply an incorrect timezone offset which then caused
it to get out of sync with the built-in Date.parse() function.
Because of this mismatch, certain dates such as 2011-12-21 were
being marked as invalid when the user had a timezone offset < 0,
e.g. in PST, since the date would become 2011-12-20 after the
incorrect timezone offset was applied.

This fixes the function that determines the timezone in the date.
It now checks for the special "%Y-%m-%d" case and returns a
timezone offset of 0 (GMT).

cc #480
  • Loading branch information
chriso committed Jan 28, 2016
1 parent eae8756 commit fada563
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@
} else {
timezone = iso8601Parts[21];
if (!timezone) {
return null;
// if no hour/minute was provided, the date is GMT
return !iso8601Parts[12] ? 0 : null;
}
if (timezone === 'z' || timezone === 'Z') {
return 0;
Expand Down

0 comments on commit fada563

Please sign in to comment.