Merge pull request #1 from samsonjs/utc-year

correct fuzzy interpretation of old years by new Date()
This commit is contained in:
Alexandr Nikitin 2015-03-04 23:43:12 +02:00
commit 05c64ef5fb

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'];