Skip to content

Commit c1cd6ae

Browse files
committed
Skip the offset replacement if it can't be determined
1 parent 8c7c9de commit c1cd6ae

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

validator.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -474,9 +474,10 @@
474474
var iso8601Parts = str.match(iso8601)
475475
, timezone, sign, hours, minutes;
476476
if (!iso8601Parts) {
477-
timezone = str.match(/(?:\s|GMT\s*)(-|\+)(\d{1,4})(\s|$)/);
477+
str = str.toLowerCase();
478+
timezone = str.match(/(?:\s|gmt\s*)(-|\+)(\d{1,4})(\s|$)/);
478479
if (!timezone) {
479-
return new Date().getTimezoneOffset();
480+
return str.indexOf('gmt') !== -1 ? 0 : null;
480481
}
481482
sign = timezone[1];
482483
var offset = timezone[2];
@@ -515,10 +516,13 @@
515516
// normalizedDate is in the user's timezone. Apply the input
516517
// timezone offset to the date so that the year and day match
517518
// the input
518-
var timezoneDifference = normalizedDate.getTimezoneOffset() -
519-
getTimezoneOffset(str);
520-
normalizedDate = new Date(normalizedDate.getTime() +
521-
60000 * timezoneDifference);
519+
var timezoneOffset = getTimezoneOffset(str);
520+
if (timezoneOffset !== null) {
521+
var timezoneDifference = normalizedDate.getTimezoneOffset() -
522+
timezoneOffset;
523+
normalizedDate = new Date(normalizedDate.getTime() +
524+
60000 * timezoneDifference);
525+
}
522526
var day = String(normalizedDate.getDate());
523527
var dayOrYear, dayOrYearMatches, year;
524528
//check for valid double digits that could be late days

0 commit comments

Comments
 (0)