mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
correct fuzzy interpretation of old years by new Date()
This commit is contained in:
parent
b0a4d5a84a
commit
f7799a1d21
1 changed files with 11 additions and 3 deletions
14
strftime.js
14
strftime.js
|
|
@ -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'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue