]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Passing isoWeek tests
authorTim Wood <washwithcare@gmail.com>
Tue, 6 Nov 2012 21:45:26 +0000 (13:45 -0800)
committerTim Wood <washwithcare@gmail.com>
Tue, 6 Nov 2012 21:45:26 +0000 (13:45 -0800)
moment.js

index 87123e3f6599e68770eb82b016ccfe67a652772f..9f706a5ce741e3f22d78e6fda0775607cd470ab6 100644 (file)
--- a/moment.js
+++ b/moment.js
     }
 
 
+    /************************************
+        Week of Year
+    ************************************/
+
+
+    function weekOfYear(mom, firstDayOfWeek, firstDayOfYear) {
+        var start = mom.clone().date(1).month(0),
+            dayOfYear = mom.diff(start, 'days') + 1,
+            week = dayOfYear - (firstDayOfWeek + mom.day()) + start.day();
+
+        if (start.day() <= firstDayOfYear) {
+            week += 7;
+        }
+
+        return week / 7 || 53;
+    }
+
+
     /************************************
         Top Level Functions
     ************************************/
             return moment.utc([this.year(), this.month() + 1, 0]).date();
         },
 
+        isoWeek : function () {
+            return weekOfYear(this, 1, 4);
+        },
+
         // If passed a language key, it will set the language for this
         // instance.  Otherwise, it will return the language configuration
         // variables for this instance.