]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Added tests for start/end of isoWeek 918/head
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 14 Jul 2013 23:31:46 +0000 (21:31 -0200)
committerIskren Chernev <iskren.chernev@gmail.com>
Sun, 14 Jul 2013 23:31:46 +0000 (21:31 -0200)
moment.js
test/moment/sod_eod.js

index d32a805c7f9afe98d67662a58476c23633058fb1..2eb512b8a70fc3cf068620cede26cb7a244e4cf5 100644 (file)
--- a/moment.js
+++ b/moment.js
@@ -73,6 +73,7 @@
             h : 'hour',
             d : 'day',
             w : 'week',
+            W : 'isoweek',
             M : 'month',
             y : 'year'
         },
                 this.date(1);
                 /* falls through */
             case 'week':
-            case 'isoWeek':
+            case 'isoweek':
             case 'day':
                 this.hours(0);
                 /* falls through */
             // weeks are a special case
             if (units === 'week') {
                 this.weekday(0);
-            } else if (units === 'isoWeek') {
-                this.isoWeekday(0);
+            } else if (units === 'isoweek') {
+                this.isoWeekday(1);
             }
 
             return this;
         },
 
         endOf: function (units) {
-            return this.startOf(units).add(units, 1).subtract('ms', 1);
+            units = normalizeUnits(units);
+            return this.startOf(units).add((units === 'isoweek' ? 'week' : units), 1).subtract('ms', 1);
         },
 
         isAfter: function (input, units) {
index 164ad82b898cb15cef82e4cf6fd3e09cac0dd208..17b928956a57db5abea0b587b76fb5774739c042 100644 (file)
@@ -121,6 +121,44 @@ exports.end_start_of = {
         test.done();
     },
 
+    "start of iso-week" : function (test) {
+        test.expect(10);
+
+        var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeek'),
+            ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('isoWeeks'),
+            ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('W');
+        test.equal(+m, +ms, "Plural or singular should work");
+        test.equal(+m, +ma, "Full or abbreviated should work");
+        test.equal(m.year(), 2011, "keep the year");
+        test.equal(m.month(), 0, "rollback to January");
+        test.equal(m.isoWeekday(), 1, "set day of iso-week");
+        test.equal(m.date(), 31, "set correct date");
+        test.equal(m.hours(), 0, "strip out the hours");
+        test.equal(m.minutes(), 0, "strip out the minutes");
+        test.equal(m.seconds(), 0, "strip out the seconds");
+        test.equal(m.milliseconds(), 0, "strip out the milliseconds");
+        test.done();
+    },
+
+    "end of iso-week" : function (test) {
+        test.expect(10);
+
+        var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeek'),
+            ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('isoWeeks'),
+            ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('W');
+        test.equal(+m, +ms, "Plural or singular should work");
+        test.equal(+m, +ma, "Full or abbreviated should work");
+        test.equal(m.year(), 2011, "keep the year");
+        test.equal(m.month(), 1, "keep the month");
+        test.equal(m.isoWeekday(), 7, "set the day of the week");
+        test.equal(m.date(), 6, "set the day");
+        test.equal(m.hours(), 23, "set the hours");
+        test.equal(m.minutes(), 59, "set the minutes");
+        test.equal(m.seconds(), 59, "set the seconds");
+        test.equal(m.milliseconds(), 999, "set the seconds");
+        test.done();
+    },
+
     "start of day" : function (test) {
         test.expect(9);