From: Matt Johnson Date: Tue, 10 Nov 2015 06:14:30 +0000 (-0800) Subject: Only call setFullYear when necessary X-Git-Tag: 2.11.0~20^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f89da2da593b4e714fa81c41b9d7fbab05affa49;p=thirdparty%2Fmoment.git Only call setFullYear when necessary --- diff --git a/src/lib/create/date-from-array.js b/src/lib/create/date-from-array.js index fd0fe524c..98cd94109 100644 --- a/src/lib/create/date-from-array.js +++ b/src/lib/create/date-from-array.js @@ -3,8 +3,8 @@ export function createDate (y, m, d, h, M, s, ms) { //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply var date = new Date(y, m, d, h, M, s, ms); - //the date constructor doesn't accept years < 1970 - if (y < 1970 && isFinite(date.getYear())) { + //the date constructor remaps years 0-99 to 1900-1999 + if (y < 100 && y >= 0 && isFinite(date.getYear())) { date.setFullYear(y); } return date; @@ -12,7 +12,9 @@ export function createDate (y, m, d, h, M, s, ms) { export function createUTCDate (y) { var date = new Date(Date.UTC.apply(null, arguments)); - if (y < 1970 && isFinite(date.getUTCFullYear())) { + + //the Date.UTC function remaps years 0-99 to 1900-1999 + if (y < 100 && y >= 0 && isFinite(date.getUTCFullYear())) { date.setUTCFullYear(y); } return date;