]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Adding plural weeks/isoWeeks methods that mirror their singular form
authorTim Wood <washwithcare@gmail.com>
Thu, 8 Nov 2012 22:52:14 +0000 (14:52 -0800)
committerTim Wood <washwithcare@gmail.com>
Thu, 8 Nov 2012 22:52:14 +0000 (14:52 -0800)
moment.js
test/moment/weeks.js

index 8dc2b8a9ab0630d38b78ff824a47cb77c8be8c84..7a4ba74699eecc57f21551bc8bd8a32441352a62 100644 (file)
--- a/moment.js
+++ b/moment.js
     // add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
     makeGetterAndSetter('year', 'FullYear');
 
-    // add days plural method
+    // add plural methods
     moment.fn.days = moment.fn.day;
+    moment.fn.weeks = moment.fn.week;
+    moment.fn.isoWeeks = moment.fn.isoWeek;
 
     /************************************
         Duration Prototype
index d262a5e6e5be49f00da808d6c36d209b260fff0e..c2f286d9e4d41f18a0baf15737801d44787e013a 100644 (file)
@@ -124,6 +124,30 @@ exports.utc = {
         test.equal(moment([2012, 0,  9]).format('W WW Wo'),  '2 02 2nd' , "Jan  9 2012 should be iso week 2");
         test.equal(moment([2012, 0, 15]).format('W WW Wo'),  '2 02 2nd' , "Jan 15 2012 should be iso week 2");
 
+        test.done();
+    },
+
+    "weeks plural year starting sunday" : function(test) {
+        test.expect(5);
+
+        test.equal(moment([2012, 0,  1]).weeks(), 1, "Jan  1 2012 should be week 1");
+        test.equal(moment([2012, 0,  7]).weeks(), 1, "Jan  7 2012 should be week 1");
+        test.equal(moment([2012, 0,  8]).weeks(), 2, "Jan  8 2012 should be week 2");
+        test.equal(moment([2012, 0, 14]).weeks(), 2, "Jan 14 2012 should be week 2");
+        test.equal(moment([2012, 0, 15]).weeks(), 3, "Jan 15 2012 should be week 3");
+
+        test.done();
+    },
+
+    "iso weeks plural year starting sunday" : function(test) {
+        test.expect(5);
+
+        test.equal(moment([2012, 0, 1]).isoWeeks(), 52, "Jan  1 2012 should be iso week 52");
+        test.equal(moment([2012, 0, 2]).isoWeeks(),  1, "Jan  2 2012 should be iso week 1");
+        test.equal(moment([2012, 0, 8]).isoWeeks(),  1, "Jan  8 2012 should be iso week 1");
+        test.equal(moment([2012, 0, 9]).isoWeeks(),  2, "Jan  9 2012 should be iso week 2");
+        test.equal(moment([2012, 0, 15]).isoWeeks(), 2, "Jan 15 2012 should be iso week 2");
+
         test.done();
     }
 };