]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Only call setFullYear when necessary
authorMatt Johnson <mj1856@hotmail.com>
Tue, 10 Nov 2015 06:14:30 +0000 (22:14 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 9 Dec 2015 06:53:35 +0000 (22:53 -0800)
src/lib/create/date-from-array.js

index fd0fe524c244207b203bf1d1e84a55079a685b7a..98cd94109e20fb42a851eaf4aeed3fc11a8bfbfd 100644 (file)
@@ -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;