correct fuzzy interpretation of old years by new Date()

This commit is contained in:
Sami Samhuri 2015-03-04 09:14:58 -08:00
parent b0a4d5a84a
commit f7799a1d21

View file

@ -280,14 +280,22 @@
}
function dateToUTC(d) {
return new Date(
d.getUTCFullYear(),
var year = d.getUTCFullYear();
var date = new Date(
year,
d.getUTCMonth(),
d.getUTCDate(),
d.getUTCHours(),
d.getUTCMinutes(),
d.getUTCSeconds(),
d.getUTCMilliseconds());
d.getUTCMilliseconds()
);
// In old dates, years is incorrectly interpreted as a 2-digit year with base 1900.
// Correct this by setting the year explicitly after the fuzzy creation process.
if (date.getFullYear() != year) {
date.setFullYear(year);
}
return date;
}
var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];