]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Test fixes for immutable API
authorLucas Sanders <butterflyhug@google.com>
Sun, 30 Oct 2016 18:27:57 +0000 (14:27 -0400)
committerLucas Sanders <butterflyhug@google.com>
Wed, 22 Mar 2017 11:00:19 +0000 (07:00 -0400)
12 files changed:
src/test/locale/el.js
src/test/moment/add_subtract.js
src/test/moment/calendar.js
src/test/moment/duration.js
src/test/moment/format.js
src/test/moment/getters_setters.js
src/test/moment/locale.js
src/test/moment/relative_time.js
src/test/moment/start_end_of.js
src/test/moment/utc.js
src/test/moment/utc_offset.js
src/test/moment/zones.js

index 738490dc37b560b0e52689182749261681304e69..fdbb35d1dccb1a1eab28d04b36ddb154fa7054c4 100644 (file)
@@ -227,11 +227,11 @@ test('calendar last week', function (assert) {
         m = moment().subtract({d: i});
         dayString = m.day() === 6 ? '[το προηγούμενο Σάββατο]' : '[την προηγούμενη] dddd';
         assert.equal(m.calendar(),       m.format(dayString + ' [' + (m.hours() % 12 === 1 ? 'στη' : 'στις') + '] LT'),  'Today - ' + i + ' days current time');
-        m.hours(1).minutes(30).seconds(0).milliseconds(0);
+        m = m.hours(1).minutes(30).seconds(0).milliseconds(0);
         assert.equal(m.calendar(),       m.format(dayString + ' [στη] LT'),  'Today - ' + i + ' days one o clock');
-        m.hours(0).minutes(0).seconds(0).milliseconds(0);
+        m = m.hours(0).minutes(0).seconds(0).milliseconds(0);
         assert.equal(m.calendar(),       m.format(dayString + ' [στις] LT'),  'Today - ' + i + ' days beginning of day');
-        m.hours(23).minutes(59).seconds(59).milliseconds(999);
+        m = m.hours(23).minutes(59).seconds(59).milliseconds(999);
         assert.equal(m.calendar(),       m.format(dayString + ' [στις] LT'),  'Today - ' + i + ' days end of day');
     }
 });
index 126a1e7612b623ebff1f7bad67be88c57778fd04..30b58bc22ac298b9f07ecfca33a628d1808afb28 100644 (file)
@@ -4,24 +4,25 @@ import moment from '../../moment';
 module('add and subtract');
 
 test('add short reverse args', function (assert) {
-    var a = moment(), b, c, d;
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a, b, c, d;
+    a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add({ms: 50}).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add({s: 1}).seconds(), 9, 'Add seconds');
     assert.equal(a.add({m: 1}).minutes(), 8, 'Add minutes');
     assert.equal(a.add({h: 1}).hours(), 7, 'Add hours');
     assert.equal(a.add({d: 1}).date(), 13, 'Add date');
-    assert.equal(a.add({w: 1}).date(), 20, 'Add week');
+    assert.equal(a.add({w: 1}).date(), 19, 'Add week');
     assert.equal(a.add({M: 1}).month(), 10, 'Add month');
     assert.equal(a.add({y: 1}).year(), 2012, 'Add year');
-    assert.equal(a.add({Q: 1}).month(), 1, 'Add quarter');
+    assert.equal(a.add({Q: 1}).month(), 0, 'Add quarter');
 
     b = moment([2010, 0, 31]).add({M: 1});
     c = moment([2010, 1, 28]).subtract({M: 1});
@@ -37,286 +38,280 @@ test('add short reverse args', function (assert) {
 });
 
 test('add long reverse args', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add({milliseconds: 50}).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add({seconds: 1}).seconds(), 9, 'Add seconds');
     assert.equal(a.add({minutes: 1}).minutes(), 8, 'Add minutes');
     assert.equal(a.add({hours: 1}).hours(), 7, 'Add hours');
     assert.equal(a.add({days: 1}).date(), 13, 'Add date');
-    assert.equal(a.add({weeks: 1}).date(), 20, 'Add week');
+    assert.equal(a.add({weeks: 1}).date(), 19, 'Add week');
     assert.equal(a.add({months: 1}).month(), 10, 'Add month');
     assert.equal(a.add({years: 1}).year(), 2012, 'Add year');
-    assert.equal(a.add({quarters: 1}).month(), 1, 'Add quarter');
+    assert.equal(a.add({quarters: 1}).month(), 0, 'Add quarter');
 });
 
 test('add long singular reverse args', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add({millisecond: 50}).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add({second: 1}).seconds(), 9, 'Add seconds');
     assert.equal(a.add({minute: 1}).minutes(), 8, 'Add minutes');
     assert.equal(a.add({hour: 1}).hours(), 7, 'Add hours');
     assert.equal(a.add({day: 1}).date(), 13, 'Add date');
-    assert.equal(a.add({week: 1}).date(), 20, 'Add week');
+    assert.equal(a.add({week: 1}).date(), 19, 'Add week');
     assert.equal(a.add({month: 1}).month(), 10, 'Add month');
     assert.equal(a.add({year: 1}).year(), 2012, 'Add year');
-    assert.equal(a.add({quarter: 1}).month(), 1, 'Add quarter');
+    assert.equal(a.add({quarter: 1}).month(), 0, 'Add quarter');
 });
 
 test('add string long reverse args', function (assert) {
-    var a = moment(), b;
-
     test.expectedDeprecations('moment().add(period, number)');
 
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
-
-    b = a.clone();
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add('millisecond', 50).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add('second', 1).seconds(), 9, 'Add seconds');
     assert.equal(a.add('minute', 1).minutes(), 8, 'Add minutes');
     assert.equal(a.add('hour', 1).hours(), 7, 'Add hours');
     assert.equal(a.add('day', 1).date(), 13, 'Add date');
-    assert.equal(a.add('week', 1).date(), 20, 'Add week');
+    assert.equal(a.add('week', 1).date(), 19, 'Add week');
     assert.equal(a.add('month', 1).month(), 10, 'Add month');
     assert.equal(a.add('year', 1).year(), 2012, 'Add year');
-    assert.equal(b.add('day', '01').date(), 13, 'Add date');
-    assert.equal(a.add('quarter', 1).month(), 1, 'Add quarter');
+    assert.equal(a.add('day', '01').date(), 13, 'Add date');
+    assert.equal(a.add('quarter', 1).month(), 0, 'Add quarter');
 });
 
 test('add string long singular reverse args', function (assert) {
-    var a = moment(), b;
-
     test.expectedDeprecations('moment().add(period, number)');
 
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
-
-    b = a.clone();
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add('seconds', 1).seconds(), 9, 'Add seconds');
     assert.equal(a.add('minutes', 1).minutes(), 8, 'Add minutes');
     assert.equal(a.add('hours', 1).hours(), 7, 'Add hours');
     assert.equal(a.add('days', 1).date(), 13, 'Add date');
-    assert.equal(a.add('weeks', 1).date(), 20, 'Add week');
+    assert.equal(a.add('weeks', 1).date(), 19, 'Add week');
     assert.equal(a.add('months', 1).month(), 10, 'Add month');
     assert.equal(a.add('years', 1).year(), 2012, 'Add year');
-    assert.equal(b.add('days', '01').date(), 13, 'Add date');
-    assert.equal(a.add('quarters', 1).month(), 1, 'Add quarter');
+    assert.equal(a.add('days', '01').date(), 13, 'Add date');
+    assert.equal(a.add('quarters', 1).month(), 0, 'Add quarter');
 });
 
 test('add string short reverse args', function (assert) {
-    var a = moment();
     test.expectedDeprecations('moment().add(period, number)');
 
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add('ms', 50).milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add('s', 1).seconds(), 9, 'Add seconds');
     assert.equal(a.add('m', 1).minutes(), 8, 'Add minutes');
     assert.equal(a.add('h', 1).hours(), 7, 'Add hours');
     assert.equal(a.add('d', 1).date(), 13, 'Add date');
-    assert.equal(a.add('w', 1).date(), 20, 'Add week');
+    assert.equal(a.add('w', 1).date(), 19, 'Add week');
     assert.equal(a.add('M', 1).month(), 10, 'Add month');
     assert.equal(a.add('y', 1).year(), 2012, 'Add year');
-    assert.equal(a.add('Q', 1).month(), 1, 'Add quarter');
+    assert.equal(a.add('Q', 1).month(), 0, 'Add quarter');
 });
 
 test('add string long', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add(50, 'millisecond').milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add(1, 'second').seconds(), 9, 'Add seconds');
     assert.equal(a.add(1, 'minute').minutes(), 8, 'Add minutes');
     assert.equal(a.add(1, 'hour').hours(), 7, 'Add hours');
     assert.equal(a.add(1, 'day').date(), 13, 'Add date');
-    assert.equal(a.add(1, 'week').date(), 20, 'Add week');
+    assert.equal(a.add(1, 'week').date(), 19, 'Add week');
     assert.equal(a.add(1, 'month').month(), 10, 'Add month');
     assert.equal(a.add(1, 'year').year(), 2012, 'Add year');
-    assert.equal(a.add(1, 'quarter').month(), 1, 'Add quarter');
+    assert.equal(a.add(1, 'quarter').month(), 0, 'Add quarter');
 });
 
 test('add string long singular', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add(50, 'milliseconds').milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add(1, 'seconds').seconds(), 9, 'Add seconds');
     assert.equal(a.add(1, 'minutes').minutes(), 8, 'Add minutes');
     assert.equal(a.add(1, 'hours').hours(), 7, 'Add hours');
     assert.equal(a.add(1, 'days').date(), 13, 'Add date');
-    assert.equal(a.add(1, 'weeks').date(), 20, 'Add week');
+    assert.equal(a.add(1, 'weeks').date(), 19, 'Add week');
     assert.equal(a.add(1, 'months').month(), 10, 'Add month');
     assert.equal(a.add(1, 'years').year(), 2012, 'Add year');
-    assert.equal(a.add(1, 'quarters').month(), 1, 'Add quarter');
+    assert.equal(a.add(1, 'quarters').month(), 0, 'Add quarter');
 });
 
 test('add string short', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add(50, 'ms').milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add(1, 's').seconds(), 9, 'Add seconds');
     assert.equal(a.add(1, 'm').minutes(), 8, 'Add minutes');
     assert.equal(a.add(1, 'h').hours(), 7, 'Add hours');
     assert.equal(a.add(1, 'd').date(), 13, 'Add date');
-    assert.equal(a.add(1, 'w').date(), 20, 'Add week');
+    assert.equal(a.add(1, 'w').date(), 19, 'Add week');
     assert.equal(a.add(1, 'M').month(), 10, 'Add month');
     assert.equal(a.add(1, 'y').year(), 2012, 'Add year');
-    assert.equal(a.add(1, 'Q').month(), 1, 'Add quarter');
+    assert.equal(a.add(1, 'Q').month(), 0, 'Add quarter');
 });
 
 test('add strings string short reversed', function (assert) {
-    var a = moment();
     test.expectedDeprecations('moment().add(period, number)');
 
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add('ms', '50').milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add('s', '1').seconds(), 9, 'Add seconds');
     assert.equal(a.add('m', '1').minutes(), 8, 'Add minutes');
     assert.equal(a.add('h', '1').hours(), 7, 'Add hours');
     assert.equal(a.add('d', '1').date(), 13, 'Add date');
-    assert.equal(a.add('w', '1').date(), 20, 'Add week');
+    assert.equal(a.add('w', '1').date(), 19, 'Add week');
     assert.equal(a.add('M', '1').month(), 10, 'Add month');
     assert.equal(a.add('y', '1').year(), 2012, 'Add year');
-    assert.equal(a.add('Q', '1').month(), 1, 'Add quarter');
+    assert.equal(a.add('Q', '1').month(), 0, 'Add quarter');
 });
 
 test('subtract strings string short reversed', function (assert) {
-    var a = moment();
     test.expectedDeprecations('moment().subtract(period, number)');
 
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.subtract('ms', '50').milliseconds(), 450, 'Subtract milliseconds');
     assert.equal(a.subtract('s', '1').seconds(), 7, 'Subtract seconds');
     assert.equal(a.subtract('m', '1').minutes(), 6, 'Subtract minutes');
     assert.equal(a.subtract('h', '1').hours(), 5, 'Subtract hours');
     assert.equal(a.subtract('d', '1').date(), 11, 'Subtract date');
-    assert.equal(a.subtract('w', '1').date(), 4, 'Subtract week');
+    assert.equal(a.subtract('w', '1').date(), 5, 'Subtract week');
     assert.equal(a.subtract('M', '1').month(), 8, 'Subtract month');
     assert.equal(a.subtract('y', '1').year(), 2010, 'Subtract year');
-    assert.equal(a.subtract('Q', '1').month(), 5, 'Subtract quarter');
+    assert.equal(a.subtract('Q', '1').month(), 6, 'Subtract quarter');
 });
 
 test('add strings string short', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add('50', 'ms').milliseconds(), 550, 'Add milliseconds');
     assert.equal(a.add('1', 's').seconds(), 9, 'Add seconds');
     assert.equal(a.add('1', 'm').minutes(), 8, 'Add minutes');
     assert.equal(a.add('1', 'h').hours(), 7, 'Add hours');
     assert.equal(a.add('1', 'd').date(), 13, 'Add date');
-    assert.equal(a.add('1', 'w').date(), 20, 'Add week');
+    assert.equal(a.add('1', 'w').date(), 19, 'Add week');
     assert.equal(a.add('1', 'M').month(), 10, 'Add month');
     assert.equal(a.add('1', 'y').year(), 2012, 'Add year');
-    assert.equal(a.add('1', 'Q').month(), 1, 'Add quarter');
+    assert.equal(a.add('1', 'Q').month(), 0, 'Add quarter');
 });
 
 test('add no string with milliseconds default', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.add(50).milliseconds(), 550, 'Add milliseconds');
 });
 
 test('subtract strings string short', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(500);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(500);
 
     assert.equal(a.subtract('50', 'ms').milliseconds(), 450, 'Subtract milliseconds');
     assert.equal(a.subtract('1', 's').seconds(), 7, 'Subtract seconds');
     assert.equal(a.subtract('1', 'm').minutes(), 6, 'Subtract minutes');
     assert.equal(a.subtract('1', 'h').hours(), 5, 'Subtract hours');
     assert.equal(a.subtract('1', 'd').date(), 11, 'Subtract date');
-    assert.equal(a.subtract('1', 'w').date(), 4, 'Subtract week');
+    assert.equal(a.subtract('1', 'w').date(), 5, 'Subtract week');
     assert.equal(a.subtract('1', 'M').month(), 8, 'Subtract month');
     assert.equal(a.subtract('1', 'y').year(), 2010, 'Subtract year');
-    assert.equal(a.subtract('1', 'Q').month(), 5, 'Subtract quarter');
+    assert.equal(a.subtract('1', 'Q').month(), 6, 'Subtract quarter');
 });
 
 test('add across DST', function (assert) {
index 8ce0b701a54ea5e00986e8188b4fbd9c5b6c37b1..c576d7e3e51e8664705a314d2ff98c7d7b64aa47 100644 (file)
@@ -6,7 +6,7 @@ import moment from '../../moment';
 module('calendar');
 
 test('passing a function', function (assert) {
-    var a  = moment().hours(13).minutes(0).seconds(0);
+    var a = moment().hours(13).minutes(0).seconds(0);
     assert.equal(moment(a).calendar(null, {
         'sameDay': function () {
             return 'h:mmA';
index c7e0ea377bf5b36353808305bb524e039a04df2e..ee0cebfe94077a3079edb9e090273c4b72c128ef 100644 (file)
@@ -605,10 +605,14 @@ test('isDuration', function (assert) {
 test('add', function (assert) {
     var d = moment.duration({months: 4, weeks: 3, days: 2});
     // for some reason, d._data._months does not get updated; use d._months instead.
-    assert.equal(d.add(1, 'month')._months, 5, 'Add months');
-    assert.equal(d.add(5, 'days')._days, 28, 'Add days');
-    assert.equal(d.add(10000)._milliseconds, 10000, 'Add milliseconds');
-    assert.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
+    d = d.add(1, 'month');
+    assert.equal(d._months, 5, 'Add months');
+    d = d.add(5, 'days');
+    assert.equal(d._days, 28, 'Add days');
+    d = d.add(10000);
+    assert.equal(d._milliseconds, 10000, 'Add milliseconds');
+    d = d.add({h: 23, m: 59});
+    assert.equal(d._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
 });
 
 test('add and bubble', function (assert) {
@@ -664,10 +668,14 @@ test('subtract and bubble', function (assert) {
 test('subtract', function (assert) {
     var d = moment.duration({months: 2, weeks: 2, days: 0, hours: 5});
     // for some reason, d._data._months does not get updated; use d._months instead.
-    assert.equal(d.subtract(1, 'months')._months, 1, 'Subtract months');
-    assert.equal(d.subtract(14, 'days')._days, 0, 'Subtract days');
-    assert.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds');
-    assert.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute');
+    d = d.subtract(1, 'months');
+    assert.equal(d._months, 1, 'Subtract months');
+    d = d.subtract(14, 'days');
+    assert.equal(d._days, 0, 'Subtract days');
+    d = d.subtract(10000);
+    assert.equal(d._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds');
+    d = d.subtract({h: 1, m: 59});
+    assert.equal(d._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute');
 });
 
 test('JSON.stringify duration', function (assert) {
index 195469a7807773f7fc55beb0699e4eae8d3f1d49..15ba293bdb5295439435b69aa36b2ddae5b51755 100644 (file)
@@ -44,7 +44,7 @@ test('format milliseconds', function (assert) {
     assert.equal(b.format('S'), '1', 'Deciseconds');
     assert.equal(b.format('SS'), '12', 'Centiseconds');
     assert.equal(b.format('SSS'), '123', 'Milliseconds');
-    b.milliseconds(789);
+    b = b.milliseconds(789);
     assert.equal(b.format('S'), '7', 'Deciseconds');
     assert.equal(b.format('SS'), '78', 'Centiseconds');
     assert.equal(b.format('SSS'), '789', 'Milliseconds');
index 063a45def1331ceb3eab6bd453f313ec0a2c5f25..f4ed95be955a2bfc2a92e885cc15f3887c18d1ed 100644 (file)
@@ -38,16 +38,17 @@ test('getters programmatic', function (assert) {
 });
 
 test('setters plural', function (assert) {
-    var a = moment();
     test.expectedDeprecations('years accessor', 'months accessor', 'dates accessor');
 
-    a.years(2011);
-    a.months(9);
-    a.dates(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(9);
+    var a = moment()
+        .years(2011)
+        .months(9)
+        .dates(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(9);
+
     assert.equal(a.years(), 2011, 'years');
     assert.equal(a.months(), 9, 'months');
     assert.equal(a.dates(), 12, 'dates');
@@ -59,14 +60,15 @@ test('setters plural', function (assert) {
 });
 
 test('setters singular', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hour(6);
-    a.minute(7);
-    a.second(8);
-    a.millisecond(9);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hour(6)
+        .minute(7)
+        .second(8)
+        .millisecond(9);
+
     assert.equal(a.year(), 2011, 'year');
     assert.equal(a.month(), 9, 'month');
     assert.equal(a.date(), 12, 'date');
@@ -78,14 +80,15 @@ test('setters singular', function (assert) {
 });
 
 test('setters', function (assert) {
-    var a = moment();
-    a.year(2011);
-    a.month(9);
-    a.date(12);
-    a.hours(6);
-    a.minutes(7);
-    a.seconds(8);
-    a.milliseconds(9);
+    var a = moment()
+        .year(2011)
+        .month(9)
+        .date(12)
+        .hours(6)
+        .minutes(7)
+        .seconds(8)
+        .milliseconds(9);
+
     assert.equal(a.year(), 2011, 'year');
     assert.equal(a.month(), 9, 'month');
     assert.equal(a.date(), 12, 'date');
@@ -97,19 +100,20 @@ test('setters', function (assert) {
 
     // Test month() behavior. See https://github.com/timrwood/moment/pull/822
     a = moment('20130531', 'YYYYMMDD');
-    a.month(3);
+    a = a.month(3);
     assert.equal(a.month(), 3, 'month edge case');
 });
 
 test('setter programmatic', function (assert) {
-    var a = moment();
-    a.set('year', 2011);
-    a.set('month', 9);
-    a.set('date', 12);
-    a.set('hours', 6);
-    a.set('minutes', 7);
-    a.set('seconds', 8);
-    a.set('milliseconds', 9);
+    var a = moment()
+        .set('year', 2011)
+        .set('month', 9)
+        .set('date', 12)
+        .set('hours', 6)
+        .set('minutes', 7)
+        .set('seconds', 8)
+        .set('milliseconds', 9);
+
     assert.equal(a.year(), 2011, 'year');
     assert.equal(a.month(), 9, 'month');
     assert.equal(a.date(), 12, 'date');
@@ -121,29 +125,29 @@ test('setter programmatic', function (assert) {
 
     // Test month() behavior. See https://github.com/timrwood/moment/pull/822
     a = moment('20130531', 'YYYYMMDD');
-    a.month(3);
+    a = a.month(3);
     assert.equal(a.month(), 3, 'month edge case');
 });
 
 test('setters programatic with weeks', function (assert) {
-    var a = moment();
-    a.set('weekYear', 2001);
-    a.set('week', 49);
-    a.set('day', 4);
+    var a = moment()
+        .set('weekYear', 2001)
+        .set('week', 49)
+        .set('day', 4);
 
     assert.equal(a.weekYear(), 2001, 'weekYear');
     assert.equal(a.week(), 49, 'week');
     assert.equal(a.day(), 4, 'day');
 
-    a.set('weekday', 1);
+    a = a.set('weekday', 1);
     assert.equal(a.weekday(), 1, 'weekday');
 });
 
 test('setters programatic with weeks ISO', function (assert) {
-    var a = moment();
-    a.set('isoWeekYear', 2001);
-    a.set('isoWeek', 49);
-    a.set('isoWeekday', 4);
+    var a = moment()
+        .set('isoWeekYear', 2001)
+        .set('isoWeek', 49)
+        .set('isoWeekday', 4);
 
     assert.equal(a.isoWeekYear(), 2001, 'isoWeekYear');
     assert.equal(a.isoWeek(), 49, 'isoWeek');
@@ -164,39 +168,23 @@ test('setters strings', function (assert) {
 test('setters - falsey values', function (assert) {
     var a = moment();
     // ensure minutes wasn't coincidentally 0 already
-    a.minutes(1);
-    a.minutes(0);
+    a = a.minutes(1);
+    a = a.minutes(0);
     assert.equal(a.minutes(), 0, 'falsey value');
 });
 
-test('chaining setters', function (assert) {
-    var a = moment();
-    a.year(2011)
-     .month(9)
-     .date(12)
-     .hours(6)
-     .minutes(7)
-     .seconds(8);
-    assert.equal(a.year(), 2011, 'year');
-    assert.equal(a.month(), 9, 'month');
-    assert.equal(a.date(), 12, 'date');
-    assert.equal(a.day(), 3, 'day');
-    assert.equal(a.hours(), 6, 'hour');
-    assert.equal(a.minutes(), 7, 'minute');
-    assert.equal(a.seconds(), 8, 'second');
-});
-
 test('setter with multiple unit values', function (assert) {
-    var a = moment();
-    a.set({
-        year: 2011,
-        month: 9,
-        date: 12,
-        hours: 6,
-        minutes: 7,
-        seconds: 8,
-        milliseconds: 9
-    });
+    var a = moment()
+        .set({
+            year: 2011,
+            month: 9,
+            date: 12,
+            hours: 6,
+            minutes: 7,
+            seconds: 8,
+            milliseconds: 9
+        });
+
     assert.equal(a.year(), 2011, 'year');
     assert.equal(a.month(), 9, 'month');
     assert.equal(a.date(), 12, 'date');
@@ -207,37 +195,39 @@ test('setter with multiple unit values', function (assert) {
     assert.equal(a.milliseconds(), 9, 'milliseconds');
 
     var c = moment([2016,0,1]);
-    assert.equal(c.set({weekYear: 2016}).weekYear(), 2016, 'week year correctly sets with object syntax');
-    assert.equal(c.set({quarter: 3}).quarter(), 3, 'quarter sets correctly with object syntax');
+       c = c.set({weekYear: 2016});
+    assert.equal(c.weekYear(), 2016, 'week year correctly sets with object syntax');
+       c = c.set({quarter: 3});
+    assert.equal(c.quarter(), 3, 'quarter sets correctly with object syntax');
 });
 
 test('day setter', function (assert) {
     var a = moment([2011, 0, 15]);
-    assert.equal(moment(a).day(0).date(), 9, 'set from saturday to sunday');
-    assert.equal(moment(a).day(6).date(), 15, 'set from saturday to saturday');
-    assert.equal(moment(a).day(3).date(), 12, 'set from saturday to wednesday');
+    assert.equal(a.day(0).date(), 9, 'set from saturday to sunday');
+    assert.equal(a.day(6).date(), 15, 'set from saturday to saturday');
+    assert.equal(a.day(3).date(), 12, 'set from saturday to wednesday');
 
     a = moment([2011, 0, 9]);
-    assert.equal(moment(a).day(0).date(), 9, 'set from sunday to sunday');
-    assert.equal(moment(a).day(6).date(), 15, 'set from sunday to saturday');
-    assert.equal(moment(a).day(3).date(), 12, 'set from sunday to wednesday');
+    assert.equal(a.day(0).date(), 9, 'set from sunday to sunday');
+    assert.equal(a.day(6).date(), 15, 'set from sunday to saturday');
+    assert.equal(a.day(3).date(), 12, 'set from sunday to wednesday');
 
     a = moment([2011, 0, 12]);
-    assert.equal(moment(a).day(0).date(), 9, 'set from wednesday to sunday');
-    assert.equal(moment(a).day(6).date(), 15, 'set from wednesday to saturday');
-    assert.equal(moment(a).day(3).date(), 12, 'set from wednesday to wednesday');
+    assert.equal(a.day(0).date(), 9, 'set from wednesday to sunday');
+    assert.equal(a.day(6).date(), 15, 'set from wednesday to saturday');
+    assert.equal(a.day(3).date(), 12, 'set from wednesday to wednesday');
 
-    assert.equal(moment(a).day(-7).date(), 2, 'set from wednesday to last sunday');
-    assert.equal(moment(a).day(-1).date(), 8, 'set from wednesday to last saturday');
-    assert.equal(moment(a).day(-4).date(), 5, 'set from wednesday to last wednesday');
+    assert.equal(a.day(-7).date(), 2, 'set from wednesday to last sunday');
+    assert.equal(a.day(-1).date(), 8, 'set from wednesday to last saturday');
+    assert.equal(a.day(-4).date(), 5, 'set from wednesday to last wednesday');
 
-    assert.equal(moment(a).day(7).date(), 16, 'set from wednesday to next sunday');
-    assert.equal(moment(a).day(13).date(), 22, 'set from wednesday to next saturday');
-    assert.equal(moment(a).day(10).date(), 19, 'set from wednesday to next wednesday');
+    assert.equal(a.day(7).date(), 16, 'set from wednesday to next sunday');
+    assert.equal(a.day(13).date(), 22, 'set from wednesday to next saturday');
+    assert.equal(a.day(10).date(), 19, 'set from wednesday to next wednesday');
 
-    assert.equal(moment(a).day(14).date(), 23, 'set from wednesday to second next sunday');
-    assert.equal(moment(a).day(20).date(), 29, 'set from wednesday to second next saturday');
-    assert.equal(moment(a).day(17).date(), 26, 'set from wednesday to second next wednesday');
+    assert.equal(a.day(14).date(), 23, 'set from wednesday to second next sunday');
+    assert.equal(a.day(20).date(), 29, 'set from wednesday to second next saturday');
+    assert.equal(a.day(17).date(), 26, 'set from wednesday to second next wednesday');
 });
 
 test('object set ordering', function (assert) {
@@ -246,24 +236,25 @@ test('object set ordering', function (assert) {
     var b = moment([2015,1,28]);
     assert.equal(b.set({date:29, year: 2016}).format('YYYY-MM-DD'), '2016-02-29', 'year is prioritized over date');
     //check a nonexistent time in US isn't set
-    var c = moment([2016,2,13]);
-    c.set({
-        hour:2,
-        minutes:30,
-        date: 14
-    });
+    var c = moment([2016,2,13])
+        .set({
+            hour:2,
+            minutes:30,
+            date: 14
+        });
     assert.equal(c.format('YYYY-MM-DDTHH:mm'), '2016-03-14T02:30', 'setting hours, minutes date puts date first allowing time set to work');
 });
 
 test('string setters', function (assert) {
-    var a = moment();
-    a.year('2011');
-    a.month('9');
-    a.date('12');
-    a.hours('6');
-    a.minutes('7');
-    a.seconds('8');
-    a.milliseconds('9');
+    var a = moment()
+        .year('2011')
+        .month('9')
+        .date('12')
+        .hours('6')
+        .minutes('7')
+        .seconds('8')
+        .milliseconds('9');
+
     assert.equal(a.year(), 2011, 'year');
     assert.equal(a.month(), 9, 'month');
     assert.equal(a.date(), 12, 'date');
@@ -288,20 +279,12 @@ test('setters across DST +1', function (assert) {
     };
 
     m = moment('2014-03-15T00:00:00-07:00').parseZone();
-    m.year(2013);
-    assert.equal(m.format(), '2013-03-15T00:00:00-08:00', 'year across +1');
-
-    m = moment('2014-03-15T00:00:00-07:00').parseZone();
-    m.month(0);
-    assert.equal(m.format(), '2014-01-15T00:00:00-08:00', 'month across +1');
-
-    m = moment('2014-03-15T00:00:00-07:00').parseZone();
-    m.date(1);
-    assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'date across +1');
+    assert.equal(m.year(2013).format(), '2013-03-15T00:00:00-08:00', 'year across +1');
+    assert.equal(m.month(0).format(), '2014-01-15T00:00:00-08:00', 'month across +1');
+    assert.equal(m.date(1).format(), '2014-03-01T00:00:00-08:00', 'date across +1');
 
     m = moment('2014-03-09T03:05:00-07:00').parseZone();
-    m.hour(0);
-    assert.equal(m.format(), '2014-03-09T00:05:00-08:00', 'hour across +1');
+    assert.equal(m.hour(0).format(), '2014-03-09T00:05:00-08:00', 'hour across +1');
 
     moment.updateOffset = oldUpdateOffset;
 });
@@ -314,28 +297,18 @@ test('setters across DST -1', function (assert) {
 
     moment.updateOffset = function (mom, keepTime) {
         if (mom.isBefore(dstAt)) {
-            mom = mom.utcOffset(-7, keepTime);
-        } else {
-            mom = mom.utcOffset(-8, keepTime);
+            return mom.utcOffset(-7, keepTime);
         }
-        return mom;
+        return mom.utcOffset(-8, keepTime);
     };
 
     m = moment('2014-11-15T00:00:00-08:00').parseZone();
-    m.year(2013);
-    assert.equal(m.format(), '2013-11-15T00:00:00-07:00', 'year across -1');
-
-    m = moment('2014-11-15T00:00:00-08:00').parseZone();
-    m.month(0);
-    assert.equal(m.format(), '2014-01-15T00:00:00-07:00', 'month across -1');
-
-    m = moment('2014-11-15T00:00:00-08:00').parseZone();
-    m.date(1);
-    assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'date across -1');
+    assert.equal(m.year(2013).format(), '2013-11-15T00:00:00-07:00', 'year across -1');
+    assert.equal(m.month(0).format(), '2014-01-15T00:00:00-07:00', 'month across -1');
+    assert.equal(m.date(1).format(), '2014-11-01T00:00:00-07:00', 'date across -1');
 
     m = moment('2014-11-02T03:30:00-08:00').parseZone();
-    m.hour(0);
-    assert.equal(m.format(), '2014-11-02T00:30:00-07:00', 'hour across -1');
+    assert.equal(m.hour(0).format(), '2014-11-02T00:30:00-07:00', 'hour across -1');
 
     moment.updateOffset = oldUpdateOffset;
 });
index fc1974f59400cb87a7f9d947f26e75f41e5496ab..19416a0435e14ad845e27bb77dfe2aedd0e58990 100644 (file)
@@ -196,10 +196,10 @@ test('instance locale method with array', function (assert) {
 test('instance getter locale substrings', function (assert) {
     var m = moment();
 
-    m.locale('fr-crap');
+    m = m.locale('fr-crap');
     assert.equal(m.locale(), 'fr', 'use substrings');
 
-    m.locale('fr-does-not-exist');
+    m = m.locale('fr-does-not-exist');
     assert.equal(m.locale(), 'fr', 'uses deep substrings');
 });
 
@@ -244,7 +244,7 @@ test('changing the global locale doesn\'t affect existing duration instances', f
 });
 
 test('duration deprecations', function (assert) {
-    test.expectedDeprecations('moment().lang()');
+    test.expectedDeprecations('duration.lang()');
     assert.equal(moment.duration().lang(), moment.duration().localeData(), 'duration.lang is the same as duration.localeData');
 });
 
@@ -431,18 +431,18 @@ test('changing the global locale doesn\'t affect existing instances', function (
     assert.equal('en', mom.locale());
 });
 
-test('setting a language on instance returns the original moment for chaining', function (assert) {
+test('setting a language on instance returns a moment for chaining', function (assert) {
     test.expectedDeprecations('moment().lang()');
     var mom = moment();
 
-    assert.equal(mom.lang('fr'), mom, 'setting the language (lang) returns the original moment for chaining');
-    assert.equal(mom.locale('it'), mom, 'setting the language (locale) returns the original moment for chaining');
+    assert.ok(moment.isMoment(mom.lang('fr')), 'setting the language (lang) returns a moment for chaining');
+    assert.ok(moment.isMoment(mom.locale('it')), 'setting the language (locale) returns a moment for chaining');
 });
 
 test('lang(key) changes the language of the instance', function (assert) {
     test.expectedDeprecations('moment().lang()');
     var m = moment().month(0);
-    m.lang('fr');
+    m = m.lang('fr');
     assert.equal(m.locale(), 'fr', 'm.lang(key) changes instance locale');
 });
 
@@ -450,11 +450,11 @@ test('moment#locale(false) resets to global locale', function (assert) {
     var m = moment();
 
     moment.locale('fr');
-    m.locale('it');
+    m = m.locale('it');
 
     assert.equal(moment.locale(), 'fr', 'global locale is it');
     assert.equal(m.locale(), 'it', 'instance locale is it');
-    m.locale(false);
+    m = m.locale(false);
     assert.equal(m.locale(), 'fr', 'instance locale reset to global locale');
 });
 
index c2bbf6fa205f8f3ccb145ff3e36faeaad3808a46..ae066160baf75eb3d1314ea55a48ecb11eff2a2c 100644 (file)
@@ -7,37 +7,37 @@ test('default thresholds fromNow', function (assert) {
     var a = moment();
 
     // Seconds to minutes threshold
-    a.subtract(44, 'seconds');
+    a = a.subtract(44, 'seconds');
     assert.equal(a.fromNow(), 'a few seconds ago', 'Below default seconds to minutes threshold');
-    a.subtract(1, 'seconds');
+    a = a.subtract(1, 'seconds');
     assert.equal(a.fromNow(), 'a minute ago', 'Above default seconds to minutes threshold');
 
     // Minutes to hours threshold
     a = moment();
-    a.subtract(44, 'minutes');
+    a = a.subtract(44, 'minutes');
     assert.equal(a.fromNow(), '44 minutes ago', 'Below default minute to hour threshold');
-    a.subtract(1, 'minutes');
+    a = a.subtract(1, 'minutes');
     assert.equal(a.fromNow(), 'an hour ago', 'Above default minute to hour threshold');
 
     // Hours to days threshold
     a = moment();
-    a.subtract(21, 'hours');
+    a = a.subtract(21, 'hours');
     assert.equal(a.fromNow(), '21 hours ago', 'Below default hours to day threshold');
-    a.subtract(1, 'hours');
+    a = a.subtract(1, 'hours');
     assert.equal(a.fromNow(), 'a day ago', 'Above default hours to day threshold');
 
     // Days to month threshold
     a = moment();
-    a.subtract(25, 'days');
+    a = a.subtract(25, 'days');
     assert.equal(a.fromNow(), '25 days ago', 'Below default days to month (singular) threshold');
-    a.subtract(1, 'days');
+    a = a.subtract(1, 'days');
     assert.equal(a.fromNow(), 'a month ago', 'Above default days to month (singular) threshold');
 
     // months to year threshold
     a = moment();
-    a.subtract(10, 'months');
+    a = a.subtract(10, 'months');
     assert.equal(a.fromNow(), '10 months ago', 'Below default days to years threshold');
-    a.subtract(1, 'month');
+    a = a.subtract(1, 'month');
     assert.equal(a.fromNow(), 'a year ago', 'Above default days to years threshold');
 });
 
@@ -45,37 +45,37 @@ test('default thresholds toNow', function (assert) {
     var a = moment();
 
     // Seconds to minutes threshold
-    a.subtract(44, 'seconds');
+    a = a.subtract(44, 'seconds');
     assert.equal(a.toNow(), 'in a few seconds', 'Below default seconds to minutes threshold');
-    a.subtract(1, 'seconds');
+    a = a.subtract(1, 'seconds');
     assert.equal(a.toNow(), 'in a minute', 'Above default seconds to minutes threshold');
 
     // Minutes to hours threshold
     a = moment();
-    a.subtract(44, 'minutes');
+    a = a.subtract(44, 'minutes');
     assert.equal(a.toNow(), 'in 44 minutes', 'Below default minute to hour threshold');
-    a.subtract(1, 'minutes');
+    a = a.subtract(1, 'minutes');
     assert.equal(a.toNow(), 'in an hour', 'Above default minute to hour threshold');
 
     // Hours to days threshold
     a = moment();
-    a.subtract(21, 'hours');
+    a = a.subtract(21, 'hours');
     assert.equal(a.toNow(), 'in 21 hours', 'Below default hours to day threshold');
-    a.subtract(1, 'hours');
+    a = a.subtract(1, 'hours');
     assert.equal(a.toNow(), 'in a day', 'Above default hours to day threshold');
 
     // Days to month threshold
     a = moment();
-    a.subtract(25, 'days');
+    a = a.subtract(25, 'days');
     assert.equal(a.toNow(), 'in 25 days', 'Below default days to month (singular) threshold');
-    a.subtract(1, 'days');
+    a = a.subtract(1, 'days');
     assert.equal(a.toNow(), 'in a month', 'Above default days to month (singular) threshold');
 
     // months to year threshold
     a = moment();
-    a.subtract(10, 'months');
+    a = a.subtract(10, 'months');
     assert.equal(a.toNow(), 'in 10 months', 'Below default days to years threshold');
-    a.subtract(1, 'month');
+    a = a.subtract(1, 'month');
     assert.equal(a.toNow(), 'in a year', 'Above default days to years threshold');
 });
 
@@ -86,18 +86,18 @@ test('custom thresholds', function (assert) {
     moment.relativeTimeThreshold('s', 25);
 
     a = moment();
-    a.subtract(24, 'seconds');
+    a = a.subtract(24, 'seconds');
     assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minute threshold, s < 30');
-    a.subtract(1, 'seconds');
+    a = a.subtract(1, 'seconds');
     assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minute threshold, s < 30');
 
     // Seconds to minutes threshold
     moment.relativeTimeThreshold('s', 55);
 
     a = moment();
-    a.subtract(54, 'seconds');
+    a = a.subtract(54, 'seconds');
     assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom seconds to minutes threshold');
-    a.subtract(1, 'seconds');
+    a = a.subtract(1, 'seconds');
     assert.equal(a.fromNow(), 'a minute ago', 'Above custom seconds to minutes threshold');
 
     moment.relativeTimeThreshold('s', 45);
@@ -106,9 +106,9 @@ test('custom thresholds', function (assert) {
     moment.relativeTimeThreshold('ss', 3);
 
     a = moment();
-    a.subtract(3, 'seconds');
+    a = a.subtract(3, 'seconds');
     assert.equal(a.fromNow(), 'a few seconds ago', 'Below custom a few seconds to seconds threshold');
-    a.subtract(1, 'seconds');
+    a = a.subtract(1, 'seconds');
     assert.equal(a.fromNow(), '4 seconds ago', 'Above custom a few seconds to seconds threshold');
 
     moment.relativeTimeThreshold('ss', 44);
@@ -116,36 +116,36 @@ test('custom thresholds', function (assert) {
     // Minutes to hours threshold
     moment.relativeTimeThreshold('m', 55);
     a = moment();
-    a.subtract(54, 'minutes');
+    a = a.subtract(54, 'minutes');
     assert.equal(a.fromNow(), '54 minutes ago', 'Below custom minutes to hours threshold');
-    a.subtract(1, 'minutes');
+    a = a.subtract(1, 'minutes');
     assert.equal(a.fromNow(), 'an hour ago', 'Above custom minutes to hours threshold');
     moment.relativeTimeThreshold('m', 45);
 
     // Hours to days threshold
     moment.relativeTimeThreshold('h', 24);
     a = moment();
-    a.subtract(23, 'hours');
+    a = a.subtract(23, 'hours');
     assert.equal(a.fromNow(), '23 hours ago', 'Below custom hours to days threshold');
-    a.subtract(1, 'hours');
+    a = a.subtract(1, 'hours');
     assert.equal(a.fromNow(), 'a day ago', 'Above custom hours to days threshold');
     moment.relativeTimeThreshold('h', 22);
 
     // Days to month threshold
     moment.relativeTimeThreshold('d', 28);
     a = moment();
-    a.subtract(27, 'days');
+    a = a.subtract(27, 'days');
     assert.equal(a.fromNow(), '27 days ago', 'Below custom days to month (singular) threshold');
-    a.subtract(1, 'days');
+    a = a.subtract(1, 'days');
     assert.equal(a.fromNow(), 'a month ago', 'Above custom days to month (singular) threshold');
     moment.relativeTimeThreshold('d', 26);
 
     // months to years threshold
     moment.relativeTimeThreshold('M', 9);
     a = moment();
-    a.subtract(8, 'months');
+    a = a.subtract(8, 'months');
     assert.equal(a.fromNow(), '8 months ago', 'Below custom days to years threshold');
-    a.subtract(1, 'months');
+    a = a.subtract(1, 'months');
     assert.equal(a.fromNow(), 'a year ago', 'Above custom days to years threshold');
     moment.relativeTimeThreshold('M', 11);
 });
@@ -163,27 +163,27 @@ test('custom rounding', function (assert) {
     moment.relativeTimeThreshold('M', 12);
 
     var a = moment.utc();
-    a.subtract({minutes: 59, seconds: 59});
+    a = a.subtract({minutes: 59, seconds: 59});
     assert.equal(a.toNow(), 'in 59 minutes', 'Round down towards the nearest minute');
 
     a = moment.utc();
-    a.subtract({hours: 23, minutes: 59, seconds: 59});
+    a = a.subtract({hours: 23, minutes: 59, seconds: 59});
     assert.equal(a.toNow(), 'in 23 hours', 'Round down towards the nearest hour');
 
     a = moment.utc();
-    a.subtract({days: 26, hours: 23, minutes: 59});
+    a = a.subtract({days: 26, hours: 23, minutes: 59});
     assert.equal(a.toNow(), 'in 26 days', 'Round down towards the nearest day (just under)');
 
     a = moment.utc();
-    a.subtract({days: 27});
+    a = a.subtract({days: 27});
     assert.equal(a.toNow(), 'in a month', 'Round down towards the nearest day (just over)');
 
     a = moment.utc();
-    a.subtract({days: 364});
+    a = a.subtract({days: 364});
     assert.equal(a.toNow(), 'in 11 months', 'Round down towards the nearest month');
 
     a = moment.utc();
-    a.subtract({years: 1, days: 364});
+    a = a.subtract({years: 1, days: 364});
     assert.equal(a.toNow(), 'in a year', 'Round down towards the nearest year');
 
     // Do not round relative time evaluation
@@ -193,7 +193,7 @@ test('custom rounding', function (assert) {
     moment.relativeTimeRounding(retainValue);
 
     a = moment.utc();
-    a.subtract({hours: 39});
+    a = a.subtract({hours: 39});
     assert.equal(a.toNow(), 'in 1.625 days', 'Round down towards the nearest year');
 
     // Restore defaults
index 723d66030af422fc72bc7a91b3c948a4ed633a5e..9f59bdba1f08572afbd9def16de4e21f03934a7c 100644 (file)
@@ -316,32 +316,23 @@ test('startOf across DST +1', function (assert) {
 
     moment.updateOffset = function (mom, keepTime) {
         if (mom.isBefore(dstAt)) {
-            mom = mom.utcOffset(-8, keepTime);
-        } else {
-            mom = mom.utcOffset(-7, keepTime);
+            return mom.utcOffset(-8, keepTime);
         }
-        return mom;
+        return mom.utcOffset(-7, keepTime);
     };
 
     m = moment('2014-03-15T00:00:00-07:00').parseZone();
-    m.startOf('y');
-    assert.equal(m.format(), '2014-01-01T00:00:00-08:00', 'startOf(\'year\') across +1');
-
-    m = moment('2014-03-15T00:00:00-07:00').parseZone();
-    m.startOf('M');
-    assert.equal(m.format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1');
+    assert.equal(m.startOf('y').format(), '2014-01-01T00:00:00-08:00', 'startOf(\'year\') across +1');
+    assert.equal(m.startOf('M').format(), '2014-03-01T00:00:00-08:00', 'startOf(\'month\') across +1');
 
     m = moment('2014-03-09T09:00:00-07:00').parseZone();
-    m.startOf('d');
-    assert.equal(m.format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1');
+    assert.equal(m.startOf('d').format(), '2014-03-09T00:00:00-08:00', 'startOf(\'day\') across +1');
 
     m = moment('2014-03-09T03:05:00-07:00').parseZone();
-    m.startOf('h');
-    assert.equal(m.format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1');
+    assert.equal(m.startOf('h').format(), '2014-03-09T03:00:00-07:00', 'startOf(\'hour\') after +1');
 
     m = moment('2014-03-09T01:35:00-08:00').parseZone();
-    m.startOf('h');
-    assert.equal(m.format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1');
+    assert.equal(m.startOf('h').format(), '2014-03-09T01:00:00-08:00', 'startOf(\'hour\') before +1');
 
     // There is no such time as 2:30-7 to try startOf('hour') across that
 
@@ -356,34 +347,25 @@ test('startOf across DST -1', function (assert) {
 
     moment.updateOffset = function (mom, keepTime) {
         if (mom.isBefore(dstAt)) {
-            mom = mom.utcOffset(-7, keepTime);
-        } else {
-            mom = mom.utcOffset(-8, keepTime);
+            return mom.utcOffset(-7, keepTime);
         }
-        return mom;
+        return mom.utcOffset(-8, keepTime);
     };
 
     m = moment('2014-11-15T00:00:00-08:00').parseZone();
-    m.startOf('y');
-    assert.equal(m.format(), '2014-01-01T00:00:00-07:00', 'startOf(\'year\') across -1');
-
-    m = moment('2014-11-15T00:00:00-08:00').parseZone();
-    m.startOf('M');
-    assert.equal(m.format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1');
+    assert.equal(m.startOf('y').format(), '2014-01-01T00:00:00-07:00', 'startOf(\'year\') across -1');
+    assert.equal(m.startOf('M').format(), '2014-11-01T00:00:00-07:00', 'startOf(\'month\') across -1');
 
     m = moment('2014-11-02T09:00:00-08:00').parseZone();
-    m.startOf('d');
-    assert.equal(m.format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1');
+    assert.equal(m.startOf('d').format(), '2014-11-02T00:00:00-07:00', 'startOf(\'day\') across -1');
 
     // note that utc offset is -8
     m = moment('2014-11-02T01:30:00-08:00').parseZone();
-    m.startOf('h');
-    assert.equal(m.format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1');
+    assert.equal(m.startOf('h').format(), '2014-11-02T01:00:00-08:00', 'startOf(\'hour\') after +1');
 
     // note that utc offset is -7
     m = moment('2014-11-02T01:30:00-07:00').parseZone();
-    m.startOf('h');
-    assert.equal(m.format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1');
+    assert.equal(m.startOf('h').format(), '2014-11-02T01:00:00-07:00', 'startOf(\'hour\') before +1');
 
     moment.updateOffset = oldUpdateOffset;
 });
index faf8157d14b5259b5520c6219ce58f494a972312..477d5fcdb2a35cd99a5f099a99363d21c3953a62 100644 (file)
@@ -5,14 +5,14 @@ module('utc');
 
 test('utc and local', function (assert) {
     var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), offset, expected;
-    m.utc();
+    m = m.utc();
     // utc
     assert.equal(m.date(), 2, 'the day should be correct for utc');
     assert.equal(m.day(), 3, 'the date should be correct for utc');
     assert.equal(m.hours(), 3, 'the hours should be correct for utc');
 
     // local
-    m.local();
+    m = m.local();
     if (m.utcOffset() < -180) {
         assert.equal(m.date(), 1, 'the date should be correct for local');
         assert.equal(m.day(), 2, 'the day should be correct for local');
index 64f4903136a849dbb4c2264f30665e4d136e0cd7..52d9db5ff7496fe5443ac74eef30710f764ac185 100644 (file)
@@ -71,50 +71,43 @@ test('change hours when changing the utc offset', function (assert) {
     assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
 
     // sanity check
-    m.utcOffset(0);
+    m = m.utcOffset(0);
     assert.equal(m.hour(), 6, 'UTC 6AM should be 6AM at +0000');
 
-    m.utcOffset(-60);
+    m = m.utcOffset(-60);
     assert.equal(m.hour(), 5, 'UTC 6AM should be 5AM at -0100');
 
-    m.utcOffset(60);
+    m = m.utcOffset(60);
     assert.equal(m.hour(), 7, 'UTC 6AM should be 7AM at +0100');
 });
 
 test('change minutes when changing the utc offset', function (assert) {
     var m = moment.utc([2000, 0, 1, 6, 31]);
 
-    m.utcOffset(0);
+    m = m.utcOffset(0);
     assert.equal(m.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
 
-    m.utcOffset(-30);
+    m = m.utcOffset(-30);
     assert.equal(m.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
 
-    m.utcOffset(30);
+    m = m.utcOffset(30);
     assert.equal(m.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
 
-    m.utcOffset(-1380);
+    m = m.utcOffset(-1380);
     assert.equal(m.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
 });
 
 test('distance from the unix epoch', function (assert) {
     var zoneA = moment(),
-        zoneB = moment(zoneA),
-        zoneC = moment(zoneA),
-        zoneD = moment(zoneA),
-        zoneE = moment(zoneA);
+        zoneB = moment(zoneA).utc(),
+        zoneC = moment(zoneA).utcOffset(60),
+        zoneD = moment(zoneA).utcOffset(-480),
+        zoneE = moment(zoneA).utcOffset(-1000);
 
-    zoneB.utc();
     assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
-
-    zoneC.utcOffset(60);
     assert.equal(+zoneA, +zoneC, 'moment should equal moment.utcOffset(60)');
-
-    zoneD.utcOffset(-480);
     assert.equal(+zoneA, +zoneD,
             'moment should equal moment.utcOffset(-480)');
-
-    zoneE.utcOffset(-1000);
     assert.equal(+zoneA, +zoneE,
             'moment should equal moment.utcOffset(-1000)');
 });
@@ -127,9 +120,9 @@ test('update offset after changing any values', function (assert) {
     moment.updateOffset = function (mom, keepTime) {
         if (doChange) {
             if (+mom > 962409600000) {
-                mom = mom.utcOffset(-120, keepTime);
+                return mom.utcOffset(-120, keepTime);
             } else {
-                mom = mom.utcOffset(-60, keepTime);
+                return mom.utcOffset(-60, keepTime);
             }
         }
         return mom;
@@ -144,7 +137,7 @@ test('update offset after changing any values', function (assert) {
     assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
     assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
 
-    m.subtract(1, 'h');
+    m = m.subtract(1, 'h');
 
     assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
     assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');
@@ -273,9 +266,9 @@ test('reset offset with moment#local', function (assert) {
 
 test('toDate', function (assert) {
     var zoneA = new Date(),
-        zoneB = zoneA.utcOffset(-720).toDate(),
-        zoneC = zoneA.utcOffset(-360).toDate(),
-        zoneD = zoneA.utcOffset(690).toDate();
+        zoneB = moment(zoneA).utcOffset(-720).toDate(),
+        zoneC = moment(zoneA).utcOffset(-360).toDate(),
+        zoneD = moment(zoneA).utcOffset(690).toDate();
 
     assert.equal(+zoneA, +zoneB, 'moment#toDate should output a date with the right unix timestamp');
     assert.equal(+zoneA, +zoneC, 'moment#toDate should output a date with the right unix timestamp');
index 3226a024806ab3af8037ebdb4c83836628a593f4..181c13f1ec773bc68a589bcb8e6776a5150852a7 100644 (file)
@@ -8,105 +8,61 @@ module('zones', {
 });
 
 test('set zone', function (assert) {
-    var zone = moment();
-
-    zone.zone(0);
-    assert.equal(zone.zone(), 0, 'should be able to set the zone to 0');
-
-    zone.zone(60);
-    assert.equal(zone.zone(), 60, 'should be able to set the zone to 60');
-
-    zone.zone(-60);
-    assert.equal(zone.zone(), -60, 'should be able to set the zone to -60');
+    var m = moment();
+    assert.equal(m.zone(0).zone(), 0, 'should be able to set the zone to 0');
+    assert.equal(m.zone(60).zone(), 60, 'should be able to set the zone to 60');
+    assert.equal(m.zone(-60).zone(), -60, 'should be able to set the zone to -60');
 });
 
 test('set zone shorthand', function (assert) {
-    var zone = moment();
-
-    zone.zone(1);
-    assert.equal(zone.zone(), 60, 'setting the zone to 1 should imply hours and convert to 60');
-
-    zone.zone(-1);
-    assert.equal(zone.zone(), -60, 'setting the zone to -1 should imply hours and convert to -60');
-
-    zone.zone(15);
-    assert.equal(zone.zone(), 900, 'setting the zone to 15 should imply hours and convert to 900');
-
-    zone.zone(-15);
-    assert.equal(zone.zone(), -900, 'setting the zone to -15 should imply hours and convert to -900');
-
-    zone.zone(16);
-    assert.equal(zone.zone(), 16, 'setting the zone to 16 should imply minutes');
-
-    zone.zone(-16);
-    assert.equal(zone.zone(), -16, 'setting the zone to -16 should imply minutes');
+    var m = moment();
+    assert.equal(m.zone(1).zone(), 60, 'setting the zone to 1 should imply hours and convert to 60');
+    assert.equal(m.zone(-1).zone(), -60, 'setting the zone to -1 should imply hours and convert to -60');
+    assert.equal(m.zone(15).zone(), 900, 'setting the zone to 15 should imply hours and convert to 900');
+    assert.equal(m.zone(-15).zone(), -900, 'setting the zone to -15 should imply hours and convert to -900');
+    assert.equal(m.zone(16).zone(), 16, 'setting the zone to 16 should imply minutes');
+    assert.equal(m.zone(-16).zone(), -16, 'setting the zone to -16 should imply minutes');
 });
 
 test('set zone with string', function (assert) {
-    var zone = moment();
-
-    zone.zone('+00:00');
-    assert.equal(zone.zone(), 0, 'set the zone with a timezone string');
-
-    zone.zone('2013-03-07T07:00:00-08:00');
-    assert.equal(zone.zone(), 480, 'set the zone with a string that does not begin with the timezone');
-
-    zone.zone('2013-03-07T07:00:00+0100');
-    assert.equal(zone.zone(), -60, 'set the zone with a string that uses the +0000 syntax');
-
-    zone.zone('2013-03-07T07:00:00+02');
-    assert.equal(zone.zone(), -120, 'set the zone with a string that uses the +00 syntax');
-
-    zone.zone('03-07-2013T07:00:00-08:00');
-    assert.equal(zone.zone(), 480, 'set the zone with a string with a non-ISO 8601 date');
+    var m = moment();
+    assert.equal(m.zone('+00:00').zone(), 0,
+            'set the zone with a timezone string');
+    assert.equal(m.zone('2013-03-07T07:00:00-08:00').zone(), 480,
+            'set the zone with a string that does not begin with the timezone');
+    assert.equal(m.zone('2013-03-07T07:00:00+0100').zone(), -60,
+            'set the zone with a string that uses the +0000 syntax');
+    assert.equal(m.zone('2013-03-07T07:00:00+02').zone(), -120,
+            'set the zone with a string that uses the +00 syntax');
+    assert.equal(m.zone('03-07-2013T07:00:00-08:00').zone(), 480,
+            'set the zone with a string with a non-ISO 8601 date');
 });
 
 test('change hours when changing the zone', function (assert) {
-    var zone = moment.utc([2000, 0, 1, 6]);
-
-    zone.zone(0);
-    assert.equal(zone.hour(), 6, 'UTC 6AM should be 6AM at +0000');
-
-    zone.zone(60);
-    assert.equal(zone.hour(), 5, 'UTC 6AM should be 5AM at -0100');
-
-    zone.zone(-60);
-    assert.equal(zone.hour(), 7, 'UTC 6AM should be 7AM at +0100');
+    var m = moment.utc([2000, 0, 1, 6]);
+    assert.equal(m.zone(0).hour(), 6, 'UTC 6AM should be 6AM at +0000');
+    assert.equal(m.zone(60).hour(), 5, 'UTC 6AM should be 5AM at -0100');
+    assert.equal(m.zone(-60).hour(), 7, 'UTC 6AM should be 7AM at +0100');
 });
 
 test('change minutes when changing the zone', function (assert) {
-    var zone = moment.utc([2000, 0, 1, 6, 31]);
-
-    zone.zone(0);
-    assert.equal(zone.format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
-
-    zone.zone(30);
-    assert.equal(zone.format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
-
-    zone.zone(-30);
-    assert.equal(zone.format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
-
-    zone.zone(1380);
-    assert.equal(zone.format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
+    var m = moment.utc([2000, 0, 1, 6, 31]);
+    assert.equal(m.zone(0).format('HH:mm'), '06:31', 'UTC 6:31AM should be 6:31AM at +0000');
+    assert.equal(m.zone(30).format('HH:mm'), '06:01', 'UTC 6:31AM should be 6:01AM at -0030');
+    assert.equal(m.zone(-30).format('HH:mm'), '07:01', 'UTC 6:31AM should be 7:01AM at +0030');
+    assert.equal(m.zone(1380).format('HH:mm'), '07:31', 'UTC 6:31AM should be 7:31AM at +1380');
 });
 
 test('distance from the unix epoch', function (assert) {
     var zoneA = moment(),
-        zoneB = moment(zoneA),
-        zoneC = moment(zoneA),
-        zoneD = moment(zoneA),
-        zoneE = moment(zoneA);
+        zoneB = moment(zoneA).utc(),
+        zoneC = moment(zoneA).zone(-60),
+        zoneD = moment(zoneA).zone(480),
+        zoneE = moment(zoneA).zone(1000);
 
-    zoneB.utc();
     assert.equal(+zoneA, +zoneB, 'moment should equal moment.utc');
-
-    zoneC.zone(-60);
     assert.equal(+zoneA, +zoneC, 'moment should equal moment.zone(-60)');
-
-    zoneD.zone(480);
     assert.equal(+zoneA, +zoneD, 'moment should equal moment.zone(480)');
-
-    zoneE.zone(1000);
     assert.equal(+zoneA, +zoneE, 'moment should equal moment.zone(1000)');
 });
 
@@ -118,9 +74,9 @@ test('update offset after changing any values', function (assert) {
     moment.updateOffset = function (mom, keepTime) {
         if (doChange) {
             if (+mom > 962409600000) {
-                mom = mom.zone(120, keepTime);
+                return mom.zone(120, keepTime);
             } else {
-                mom = mom.zone(60, keepTime);
+                return mom.zone(60, keepTime);
             }
         }
         return mom;
@@ -135,7 +91,7 @@ test('update offset after changing any values', function (assert) {
     assert.equal(m.format('ZZ'), '-0200', 'should be at -0200');
     assert.equal(m.format('HH:mm'), '23:00', '1AM at +0000 should be 11PM at -0200 timezone');
 
-    m.subtract(1, 'h');
+    m = m.subtract(1, 'h');
 
     assert.equal(m.format('ZZ'), '-0100', 'should be at -0100');
     assert.equal(m.format('HH:mm'), '23:00', '12AM at +0000 should be 11PM at -0100 timezone');