mirror of
https://github.com/samsonjs/strftime.git
synced 2026-04-27 14:57:37 +00:00
Merge pull request #1 from samsonjs/utc-year
correct fuzzy interpretation of old years by new Date()
This commit is contained in:
commit
05c64ef5fb
1 changed files with 11 additions and 3 deletions
14
strftime.js
14
strftime.js
|
|
@ -280,14 +280,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateToUTC(d) {
|
function dateToUTC(d) {
|
||||||
return new Date(
|
var year = d.getUTCFullYear();
|
||||||
d.getUTCFullYear(),
|
var date = new Date(
|
||||||
|
year,
|
||||||
d.getUTCMonth(),
|
d.getUTCMonth(),
|
||||||
d.getUTCDate(),
|
d.getUTCDate(),
|
||||||
d.getUTCHours(),
|
d.getUTCHours(),
|
||||||
d.getUTCMinutes(),
|
d.getUTCMinutes(),
|
||||||
d.getUTCSeconds(),
|
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'];
|
var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue