},
jshint: {
all: ["Gruntfile.js", "moment.js", "lang/**/*.js"],
+ test: ["test/moment/*.js"],
options: {
"node" : true,
"browser" : true,
var moment = require("../../moment");
exports.add = {
- "add short" : function(test) {
+ "add short" : function (test) {
test.expect(12);
- var a = moment();
+ var a = moment(), b, c;
a.year(2011);
a.month(9);
a.date(12);
a.seconds(8);
a.milliseconds(500);
- test.equal(a.add({ms:50}).milliseconds(), 550, 'Add milliseconds');
- test.equal(a.add({s:1}).seconds(), 9, 'Add seconds');
- test.equal(a.add({m:1}).minutes(), 8, 'Add minutes');
- test.equal(a.add({h:1}).hours(), 7, 'Add hours');
- test.equal(a.add({d:1}).date(), 13, 'Add date');
- test.equal(a.add({w:1}).date(), 20, 'Add week');
- test.equal(a.add({M:1}).month(), 10, 'Add month');
- test.equal(a.add({y:1}).year(), 2012, 'Add year');
+ test.equal(a.add({ms: 50}).milliseconds(), 550, 'Add milliseconds');
+ test.equal(a.add({s: 1}).seconds(), 9, 'Add seconds');
+ test.equal(a.add({m: 1}).minutes(), 8, 'Add minutes');
+ test.equal(a.add({h: 1}).hours(), 7, 'Add hours');
+ test.equal(a.add({d: 1}).date(), 13, 'Add date');
+ test.equal(a.add({w: 1}).date(), 20, 'Add week');
+ test.equal(a.add({M: 1}).month(), 10, 'Add month');
+ test.equal(a.add({y: 1}).year(), 2012, 'Add year');
- var b = moment([2010, 0, 31]).add({M:1});
- var c = moment([2010, 1, 28]).subtract({M:1});
+ b = moment([2010, 0, 31]).add({M: 1});
+ c = moment([2010, 1, 28]).subtract({M: 1});
test.equal(b.month(), 1, 'add month, jan 31st to feb 28th');
test.equal(b.date(), 28, 'add month, jan 31st to feb 28th');
test.done();
},
- "add long" : function(test) {
+ "add long" : function (test) {
test.expect(8);
var a = moment();
a.seconds(8);
a.milliseconds(500);
- test.equal(a.add({milliseconds:50}).milliseconds(), 550, 'Add milliseconds');
- test.equal(a.add({seconds:1}).seconds(), 9, 'Add seconds');
- test.equal(a.add({minutes:1}).minutes(), 8, 'Add minutes');
- test.equal(a.add({hours:1}).hours(), 7, 'Add hours');
- test.equal(a.add({days:1}).date(), 13, 'Add date');
- test.equal(a.add({weeks:1}).date(), 20, 'Add week');
- test.equal(a.add({months:1}).month(), 10, 'Add month');
- test.equal(a.add({years:1}).year(), 2012, 'Add year');
+ test.equal(a.add({milliseconds: 50}).milliseconds(), 550, 'Add milliseconds');
+ test.equal(a.add({seconds: 1}).seconds(), 9, 'Add seconds');
+ test.equal(a.add({minutes: 1}).minutes(), 8, 'Add minutes');
+ test.equal(a.add({hours: 1}).hours(), 7, 'Add hours');
+ test.equal(a.add({days: 1}).date(), 13, 'Add date');
+ test.equal(a.add({weeks: 1}).date(), 20, 'Add week');
+ test.equal(a.add({months: 1}).month(), 10, 'Add month');
+ test.equal(a.add({years: 1}).year(), 2012, 'Add year');
test.done();
},
- "add long singular" : function(test) {
+ "add long singular" : function (test) {
test.expect(8);
var a = moment();
a.seconds(8);
a.milliseconds(500);
- test.equal(a.add({millisecond:50}).milliseconds(), 550, 'Add milliseconds');
- test.equal(a.add({second:1}).seconds(), 9, 'Add seconds');
- test.equal(a.add({minute:1}).minutes(), 8, 'Add minutes');
- test.equal(a.add({hour:1}).hours(), 7, 'Add hours');
- test.equal(a.add({day:1}).date(), 13, 'Add date');
- test.equal(a.add({week:1}).date(), 20, 'Add week');
- test.equal(a.add({month:1}).month(), 10, 'Add month');
- test.equal(a.add({year:1}).year(), 2012, 'Add year');
+ test.equal(a.add({millisecond: 50}).milliseconds(), 550, 'Add milliseconds');
+ test.equal(a.add({second: 1}).seconds(), 9, 'Add seconds');
+ test.equal(a.add({minute: 1}).minutes(), 8, 'Add minutes');
+ test.equal(a.add({hour: 1}).hours(), 7, 'Add hours');
+ test.equal(a.add({day: 1}).date(), 13, 'Add date');
+ test.equal(a.add({week: 1}).date(), 20, 'Add week');
+ test.equal(a.add({month: 1}).month(), 10, 'Add month');
+ test.equal(a.add({year: 1}).year(), 2012, 'Add year');
test.done();
},
- "add string long" : function(test) {
+ "add string long" : function (test) {
test.expect(9);
- var a = moment();
+ var a = moment(), b;
a.year(2011);
a.month(9);
a.date(12);
a.seconds(8);
a.milliseconds(500);
- var b = a.clone();
+ b = a.clone();
test.equal(a.add('millisecond', 50).milliseconds(), 550, 'Add milliseconds');
test.equal(a.add('second', 1).seconds(), 9, 'Add seconds');
test.done();
},
- "add string long singular" : function(test) {
+ "add string long singular" : function (test) {
test.expect(9);
- var a = moment();
+ var a = moment(), b;
a.year(2011);
a.month(9);
a.date(12);
a.seconds(8);
a.milliseconds(500);
- var b = a.clone();
+ b = a.clone();
test.equal(a.add('milliseconds', 50).milliseconds(), 550, 'Add milliseconds');
test.equal(a.add('seconds', 1).seconds(), 9, 'Add seconds');
test.done();
},
- "add string short" : function(test) {
+ "add string short" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "add string long reverse args" : function(test) {
+ "add string long reverse args" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "add string long singular reverse args" : function(test) {
+ "add string long singular reverse args" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "add string short reverse args" : function(test) {
+ "add string short reverse args" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "add across DST" : function(test) {
+ "add across DST" : function (test) {
test.expect(3);
- var a = moment(new Date(2011, 2, 12, 5, 0, 0));
- var b = moment(new Date(2011, 2, 12, 5, 0, 0));
- var c = moment(new Date(2011, 2, 12, 5, 0, 0));
- var d = moment(new Date(2011, 2, 12, 5, 0, 0));
+ var a = moment(new Date(2011, 2, 12, 5, 0, 0)),
+ b = moment(new Date(2011, 2, 12, 5, 0, 0)),
+ c = moment(new Date(2011, 2, 12, 5, 0, 0)),
+ d = moment(new Date(2011, 2, 12, 5, 0, 0));
a.add('days', 1);
b.add('hours', 24);
c.add('months', 1);
var moment = require("../../moment");
exports.create = {
- "array" : function(test) {
+ "array" : function (test) {
test.expect(8);
test.ok(moment([2010]).toDate() instanceof Date, "[2010]");
test.ok(moment([2010, 1]).toDate() instanceof Date, "[2010, 1]");
test.done();
},
- "array copying": function(test) {
+ "array copying": function (test) {
var importantArray = [2009, 11];
test.expect(1);
moment(importantArray);
test.done();
},
- "multi format array copying": function(test) {
+ "multi format array copying": function (test) {
var importantArray = ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY'];
test.expect(1);
moment('1999-02-13', importantArray);
test.done();
},
- "number" : function(test) {
+ "number" : function (test) {
test.expect(3);
test.ok(moment(1000).toDate() instanceof Date, "1000");
test.ok((moment(1000).valueOf() === 1000), "testing valueOf");
test.done();
},
- "unix" : function(test) {
+ "unix" : function (test) {
test.expect(8);
test.equal(moment.unix(1).valueOf(), 1000, "1 unix timestamp == 1000 Date.valueOf");
test.equal(moment(1000).unix(), 1, "1000 Date.valueOf == 1 unix timestamp");
test.done();
},
- "date" : function(test) {
+ "date" : function (test) {
test.expect(1);
test.ok(moment(new Date()).toDate() instanceof Date, "new Date()");
test.done();
},
- "date mutation" : function(test) {
+ "date mutation" : function (test) {
test.expect(1);
var a = new Date();
test.ok(moment(a).toDate() !== a, "the date moment uses should not be the date passed in");
test.done();
},
- "moment" : function(test) {
+ "moment" : function (test) {
test.expect(2);
test.ok(moment(moment()).toDate() instanceof Date, "moment(moment())");
test.ok(moment(moment(moment())).toDate() instanceof Date, "moment(moment(moment()))");
test.done();
},
- "cloning moment should only copy own properties" : function(test) {
+ "cloning moment should only copy own properties" : function (test) {
test.expect(2);
test.ok(!moment().clone().hasOwnProperty('month'), "Should not clone prototype methods");
test.ok(!moment().clone().hasOwnProperty('_lang'), "Should not clone prototype objects");
test.done();
},
- "undefined" : function(test) {
+ "undefined" : function (test) {
test.expect(1);
test.ok(moment().toDate() instanceof Date, "undefined");
test.done();
},
- "string without format" : function(test) {
+ "string without format" : function (test) {
test.expect(2);
test.ok(moment("Aug 9, 1995").toDate() instanceof Date, "Aug 9, 1995");
test.ok(moment("Mon, 25 Dec 1995 13:30:00 GMT").toDate() instanceof Date, "Mon, 25 Dec 1995 13:30:00 GMT");
test.done();
},
- "string without format - json" : function(test) {
+ "string without format - json" : function (test) {
test.expect(5);
test.equal(moment("Date(1325132654000)").valueOf(), 1325132654000, "Date(1325132654000)");
test.equal(moment("Date(-1325132654000)").valueOf(), -1325132654000, "Date(-1325132654000)");
test.done();
},
- "string with format dropped am/pm bug" : function(test) {
+ "string with format dropped am/pm bug" : function (test) {
moment.lang('en');
test.expect(3);
test.done();
},
- "empty string with formats" : function(test) {
+ "empty string with formats" : function (test) {
test.expect(3);
test.equal(moment(' ', 'MM').format('YYYY-MM-DD HH:mm:ss'), '0000-01-01 00:00:00', 'should not break if input is an empty string');
test.done();
},
- "matching am/pm" : function(test) {
+ "matching am/pm" : function (test) {
test.expect(13);
test.equal(moment('2012-09-03T03:00PM', 'YYYY-MM-DDThh:mmA').format('YYYY-MM-DDThh:mmA'), '2012-09-03T03:00PM', 'am/pm should parse correctly for PM');
test.done();
},
- "string with format" : function(test) {
+ "string with format" : function (test) {
moment.lang('en');
var a = [
['MM-DD-YYYY', '12-02-1999'],
test.done();
},
- "unix timestamp format" : function(test) {
- var formats = ['X', 'X.S', 'X.SS', 'X.SSS'];
+ "unix timestamp format" : function (test) {
+ var formats = ['X', 'X.S', 'X.SS', 'X.SSS'], i, format;
test.expect(formats.length * 4);
- for (var i = 0; i < formats.length; i++) {
- var format = formats[i];
+ for (i = 0; i < formats.length; i++) {
+ format = formats[i];
test.equal(moment('1234567890', format).valueOf(), 1234567890 * 1000, format + " matches timestamp without milliseconds");
test.equal(moment('1234567890.1', format).valueOf(), 1234567890 * 1000 + 100, format + " matches timestamp with deciseconds");
test.equal(moment('1234567890.12', format).valueOf(), 1234567890 * 1000 + 120, format + " matches timestamp with centiseconds");
test.done();
},
- "string with format no separators" : function(test) {
+ "string with format no separators" : function (test) {
moment.lang('en');
var a = [
['MMDDYYYY', '12021999'],
['DDMMYYYY', '12021999'],
['YYYYMMDD', '19991202'],
['DDMMMYYYY', '10Sep2001']
- ],i;
+ ], i;
test.expect(a.length);
test.done();
},
- "string with format (timezone)" : function(test) {
+ "string with format (timezone)" : function (test) {
test.expect(8);
test.equal(moment('5 -0700', 'H ZZ').toDate().getUTCHours(), 12, 'parse hours "5 -0700" ---> "H ZZ"');
test.equal(moment('5 -07:00', 'H Z').toDate().getUTCHours(), 12, 'parse hours "5 -07:00" ---> "H Z"');
test.equal(moment('5 -0730', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours "5 -0730" ---> "H ZZ"');
- test.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours "5 -07:30" ---> "H Z"');
+ test.equal(moment('5 -07:30', 'H Z').toDate().getUTCMinutes(), 30, 'parse hours "5 -07:0" ---> "H Z"');
test.equal(moment('5 +0100', 'H ZZ').toDate().getUTCHours(), 4, 'parse hours "5 +0100" ---> "H ZZ"');
test.equal(moment('5 +01:00', 'H Z').toDate().getUTCHours(), 4, 'parse hours "5 +01:00" ---> "H Z"');
test.equal(moment('5 +0130', 'H ZZ').toDate().getUTCMinutes(), 30, 'parse hours "5 +0130" ---> "H ZZ"');
test.done();
},
- "string with format (timezone offset)" : function(test) {
+ "string with format (timezone offset)" : function (test) {
+ var a, b, c, d, e, f;
test.expect(4);
- var a = new Date(Date.UTC(2011, 0, 1, 1));
- var b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z');
+ a = new Date(Date.UTC(2011, 0, 1, 1));
+ b = moment('2011 1 1 0 -01:00', 'YYYY MM DD HH Z');
test.equal(a.getHours(), b.hours(), 'date created with utc == parsed string with timezone offset');
test.equal(+a, +b, 'date created with utc == parsed string with timezone offset');
- var c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z');
- var d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z');
+ c = moment('2011 2 1 10 -05:00', 'YYYY MM DD HH Z');
+ d = moment('2011 2 1 8 -07:00', 'YYYY MM DD HH Z');
test.equal(c.hours(), d.hours(), '10 am central time == 8 am pacific time');
- var e = moment.utc('Fri, 20 Jul 2012 17:15:00', 'ddd, DD MMM YYYY HH:mm:ss');
- var f = moment.utc('Fri, 20 Jul 2012 10:15:00 -0700', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
+ e = moment.utc('Fri, 20 Jul 2012 17:15:00', 'ddd, DD MMM YYYY HH:mm:ss');
+ f = moment.utc('Fri, 20 Jul 2012 10:15:00 -0700', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
test.equal(e.hours(), f.hours(), 'parse timezone offset in utc');
test.done();
},
- "string with array of formats" : function(test) {
+ "string with array of formats" : function (test) {
test.expect(14);
test.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '11 02 1999', 'switching month and day');
test.done();
},
- "string with format - years" : function(test) {
+ "string with format - years" : function (test) {
test.expect(4);
test.equal(moment('67', 'YY').format('YYYY'), '2067', '67 > 2067');
test.equal(moment('68', 'YY').format('YYYY'), '2068', '68 > 2068');
test.done();
},
- "implicit cloning" : function(test) {
+ "implicit cloning" : function (test) {
test.expect(2);
- var momentA = moment([2011, 10, 10]);
- var momentB = moment(momentA);
+ var momentA = moment([2011, 10, 10]),
+ momentB = moment(momentA);
momentA.month(5);
test.equal(momentB.month(), 10, "Calling moment() on a moment will create a clone");
test.equal(momentA.month(), 5, "Calling moment() on a moment will create a clone");
test.done();
},
- "explicit cloning" : function(test) {
+ "explicit cloning" : function (test) {
test.expect(2);
- var momentA = moment([2011, 10, 10]);
- var momentB = momentA.clone();
+ var momentA = moment([2011, 10, 10]),
+ momentB = momentA.clone();
momentA.month(5);
test.equal(momentB.month(), 10, "Calling moment() on a moment will create a clone");
test.equal(momentA.month(), 5, "Calling moment() on a moment will create a clone");
test.done();
},
- "cloning carrying over utc mode" : function(test) {
+ "cloning carrying over utc mode" : function (test) {
test.expect(8);
test.equal(moment().local().clone()._isUTC, false, "An explicit cloned local moment should have _isUTC == false");
test.done();
},
- "parsing iso" : function(test) {
- var offset = moment([2011, 9, 08]).zone();
- var pad = function(input) {
- if (input < 10) {
- return '0' + input;
- }
- return '' + input;
- }
- var hourOffset = (offset > 0) ? Math.floor(offset / 60) : Math.ceil(offset / 60);
- var minOffset = offset - (hourOffset * 60);
- var tz = (offset > 0) ? '-' + pad(hourOffset) + ':' + pad(minOffset) : '+' + pad(-hourOffset) + ':' + pad(-minOffset);
- var tz2 = tz.replace(':', '');
- var formats = [
- ['2011-10-08', '2011-10-08T00:00:00.000' + tz],
- ['2011-10-08T18', '2011-10-08T18:00:00.000' + tz],
- ['2011-10-08T18:04', '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
- ['2011-10-08T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
- ['2011-10-08T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
- ['2011-10-08 18', '2011-10-08T18:00:00.000' + tz],
- ['2011-10-08 18:04', '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08 18:04:20', '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
- ['2011-10-08 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
- ['2011-10-08 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
- ['2011-10-08 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
- ['2011-10-08 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz]
- ];
+ "parsing iso" : function (test) {
+ var offset = moment([2011, 9, 08]).zone(),
+ pad = function (input) {
+ if (input < 10) {
+ return '0' + input;
+ }
+ return '' + input;
+ },
+ hourOffset = (offset > 0) ? Math.floor(offset / 60) : Math.ceil(offset / 60),
+ minOffset = offset - (hourOffset * 60),
+ tz = (offset > 0) ? '-' + pad(hourOffset) + ':' + pad(minOffset) : '+' + pad(-hourOffset) + ':' + pad(-minOffset),
+ tz2 = tz.replace(':', ''),
+ formats = [
+ ['2011-10-08', '2011-10-08T00:00:00.000' + tz],
+ ['2011-10-08T18', '2011-10-08T18:00:00.000' + tz],
+ ['2011-10-08T18:04', '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08T18:04' + tz, '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08T18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08T18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08T18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08T18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
+ ['2011-10-08T18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
+ ['2011-10-08T18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz],
+ ['2011-10-08 18', '2011-10-08T18:00:00.000' + tz],
+ ['2011-10-08 18:04', '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08 18:04:20', '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08 18:04' + tz, '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08 18:04:20' + tz, '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08 18:04' + tz2, '2011-10-08T18:04:00.000' + tz],
+ ['2011-10-08 18:04:20' + tz2, '2011-10-08T18:04:20.000' + tz],
+ ['2011-10-08 18:04:20.1' + tz2, '2011-10-08T18:04:20.100' + tz],
+ ['2011-10-08 18:04:20.11' + tz2, '2011-10-08T18:04:20.110' + tz],
+ ['2011-10-08 18:04:20.111' + tz2, '2011-10-08T18:04:20.111' + tz]
+ ], i;
test.expect(formats.length);
- for (var i = 0; i < formats.length; i++) {
+ for (i = 0; i < formats.length; i++) {
test.equal(formats[i][1], moment(formats[i][0]).format('YYYY-MM-DDTHH:mm:ss.SSSZ'), "moment should be able to parse ISO " + formats[i][0]);
}
test.done();
},
- "parsing iso with T" : function(test) {
+ "parsing iso with T" : function (test) {
test.expect(9);
test.equal(moment('2011-10-08T18')._f, "YYYY-MM-DDTHH", "should include 'T' in the format");
test.done();
},
- "parsing iso Z timezone" : function(test) {
+ "parsing iso Z timezone" : function (test) {
var i,
formats = [
['2011-10-08T18:04Z', '2011-10-08T18:04:00.000+00:00'],
test.done();
},
- "parsing iso Z timezone into local" : function(test) {
+ "parsing iso Z timezone into local" : function (test) {
test.expect(1);
var m = moment('2011-10-08T18:04:20.111Z');
test.done();
},
- "null" : function(test) {
+ "null" : function (test) {
test.expect(3);
test.equal(moment(''), null, "Calling moment('')");
test.equal(moment(null), null, "Calling moment(null)");
test.done();
},
- "first century" : function(test) {
+ "first century" : function (test) {
test.expect(9);
test.equal(moment([0, 0, 1]).format("YYYY-MM-DD"), "0000-01-01", "Year AD 0");
test.equal(moment([99, 0, 1]).format("YYYY-MM-DD"), "0099-01-01", "Year AD 99");
test.done();
},
- "six digit years" : function(test) {
+ "six digit years" : function (test) {
test.expect(8);
test.equal(moment([-270000, 0, 1]).format("YYYYY-MM-DD"), "-270000-01-01", "format BC 270,001");
test.equal(moment([ 270000, 0, 1]).format("YYYYY-MM-DD"), "270000-01-01", "format AD 270,000");
test.done();
},
- "negative four digit years" : function(test) {
+ "negative four digit years" : function (test) {
test.expect(2);
test.equal(moment("-1000-01-01", "YYYYY-MM-DD").toDate().getFullYear(), -1000, "parse BC 1,001");
test.equal(moment.utc("-1000-01-01", "YYYYY-MM-DD").toDate().getUTCFullYear(), -1000, "parse utc BC 1,001");
var moment = require("../../moment");
exports.days_in_month = {
- "days in month" : function(test) {
+ "days in month" : function (test) {
test.expect(24);
- var months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- for (var i = 0; i < 12; i++) {
+ var months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], i;
+ for (i = 0; i < 12; i++) {
test.equal(moment([2012, i]).daysInMonth(),
months[i],
- moment([2012, i]).format('L') + " should have " + months[i] + " days. (beginning of month " + i + ')')
+ moment([2012, i]).format('L') + " should have " + months[i] + " days. (beginning of month " + i + ')');
}
- for (var i = 0; i < 12; i++) {
+ for (i = 0; i < 12; i++) {
test.equal(moment([2012, i, months[i]]).daysInMonth(),
months[i],
- moment([2012, i, months[i]]).format('L') + " should have " + months[i] + " days. (end of month " + i + ')')
+ moment([2012, i, months[i]]).format('L') + " should have " + months[i] + " days. (end of month " + i + ')');
}
test.done();
},
- "days in month leap years" : function(test) {
+ "days in month leap years" : function (test) {
test.expect(4);
test.equal(moment([2010, 1]).daysInMonth(), 28, "Feb 2010 should have 28 days");
test.equal(moment([2100, 1]).daysInMonth(), 28, "Feb 2100 should have 28 days");
}
exports.diff = {
- "diff" : function(test) {
+ "diff" : function (test) {
test.expect(5);
test.equal(moment(1000).diff(0), 1000, "1 second - 0 = 1000");
test.done();
},
- "diff key after" : function(test) {
+ "diff key after" : function (test) {
test.expect(10);
test.equal(moment([2010]).diff([2011], 'years'), -1, "year diff");
test.done();
},
- "diff key before" : function(test) {
+ "diff key before" : function (test) {
test.expect(10);
test.equal(moment([2011]).diff([2010], 'years'), 1, "year diff");
test.done();
},
- "diff key before singular" : function(test) {
+ "diff key before singular" : function (test) {
test.expect(10);
test.equal(moment([2011]).diff([2010], 'year'), 1, "year diff singular");
test.done();
},
- "diff key before abbreviated" : function(test) {
+ "diff key before abbreviated" : function (test) {
test.expect(10);
test.equal(moment([2011]).diff([2010], 'y'), 1, "year diff abbreviated");
test.done();
},
- "diff month" : function(test) {
+ "diff month" : function (test) {
test.expect(1);
test.equal(moment([2011, 0, 31]).diff([2011, 2, 1], 'months'), -1, "month diff");
test.done();
},
- "diff across DST" : function(test) {
+ "diff across DST" : function (test) {
var dst = dstForYear(2012), a, b, daysInMonth;
if (!dst) {
console.log("No DST?");
test.done();
},
- "diff overflow" : function(test) {
+ "diff overflow" : function (test) {
test.expect(4);
test.equal(moment([2011]).diff([2010], 'months'), 12, "month diff");
test.done();
},
- "diff between utc and local" : function(test) {
+ "diff between utc and local" : function (test) {
test.expect(7);
test.equal(moment([2011]).utc().diff([2010], 'years'), 1, "year diff");
test.done();
},
- "diff floored" : function(test) {
+ "diff floored" : function (test) {
test.expect(7);
test.equal(moment([2010, 0, 1, 23]).diff([2010], 'day'), 0, "23 hours = 0 days");
test.done();
},
- "year diffs include dates" : function(test) {
+ "year diffs include dates" : function (test) {
test.expect(1);
test.ok(moment([2012, 1, 19]).diff(moment([2002, 1, 20]), 'years', true) < 10, "year diff should include date of month");
// due to floating point math errors, these tests just need to be accurate within 0.00000001
equal(test, moment([2012, 0, 1]).diff([2012, 1, 1], 'months', true), -1, 'Jan 1 to Feb 1 should be 1 month');
- equal(test, moment([2012, 0, 1]).diff([2012, 0, 1, 12], 'months', true), -0.5/31, 'Jan 1 to Jan 1 noon should be 0.5/31 months');
+ equal(test, moment([2012, 0, 1]).diff([2012, 0, 1, 12], 'months', true), -0.5 / 31, 'Jan 1 to Jan 1 noon should be 0.5 / 31 months');
equal(test, moment([2012, 0, 15]).diff([2012, 1, 15], 'months', true), -1, 'Jan 15 to Feb 15 should be 1 month');
equal(test, moment([2012, 0, 28]).diff([2012, 1, 28], 'months', true), -1, 'Jan 28 to Feb 28 should be 1 month');
- equal(test, moment([2012, 0, 31]).diff([2012, 1, 29], 'months', true), -1 + (2/30), 'Jan 31 to Feb 29 should be 1 - (2/30) months');
- equal(test, moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), -2 + (30/31), 'Jan 31 to Mar 1 should be 2 - (30/31) months');
- equal(test, moment([2012, 0, 31]).diff([2012, 2, 1, 12], 'months', true), -2 + (29.5/31), 'Jan 31 to Mar 1 should be 2 - (29.5/31) months');
- equal(test, moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true), -(30 / 31), 'Jan 1 to Jan 31 should be 30/31 months');
+ equal(test, moment([2012, 0, 31]).diff([2012, 1, 29], 'months', true), -1 + (2 / 30), 'Jan 31 to Feb 29 should be 1 - (2 / 30) months');
+ equal(test, moment([2012, 0, 31]).diff([2012, 2, 1], 'months', true), -2 + (30 / 31), 'Jan 31 to Mar 1 should be 2 - (30 / 31) months');
+ equal(test, moment([2012, 0, 31]).diff([2012, 2, 1, 12], 'months', true), -2 + (29.5 / 31), 'Jan 31 to Mar 1 should be 2 - (29.5 / 31) months');
+ equal(test, moment([2012, 0, 1]).diff([2012, 0, 31], 'months', true), -(30 / 31), 'Jan 1 to Jan 31 should be 30 / 31 months');
test.done();
},
equal(test, moment([2012, 11, 31]).diff([2013, 11, 31], 'years', true), -1, 'Dec 31 2012 to Dec 31 2013 should be 1 year');
equal(test, moment([2012, 0, 1]).diff([2013, 6, 1], 'years', true), -1.5, 'Jan 1 2012 to Jul 1 2013 should be 1.5 years');
equal(test, moment([2012, 0, 31]).diff([2013, 6, 31], 'years', true), -1.5, 'Jan 31 2012 to Jul 31 2013 should be 1.5 years');
- equal(test, moment([2012, 0, 1]).diff([2013, 0, 1, 12], 'years', true), -1-(0.5/31)/12, 'Jan 1 2012 to Jan 1 2013 noon should be 1+(0.5/31)/12 years');
- equal(test, moment([2012, 0, 1]).diff([2013, 6, 1, 12], 'years', true), -1.5-(0.5/31)/12, 'Jan 1 2012 to Jul 1 2013 noon should be 1.5+(0.5/31)/12 years');
- equal(test, moment([2012, 1, 29]).diff([2013, 1, 28], 'years', true), -1 + (1/28.5)/12, 'Feb 29 2012 to Feb 28 2013 should be 1-(1/28.5)/12 years');
+ equal(test, moment([2012, 0, 1]).diff([2013, 0, 1, 12], 'years', true), -1 - (0.5 / 31) / 12, 'Jan 1 2012 to Jan 1 2013 noon should be 1+(0.5 / 31) / 12 years');
+ equal(test, moment([2012, 0, 1]).diff([2013, 6, 1, 12], 'years', true), -1.5 - (0.5 / 31) / 12, 'Jan 1 2012 to Jul 1 2013 noon should be 1.5+(0.5 / 31) / 12 years');
+ equal(test, moment([2012, 1, 29]).diff([2013, 1, 28], 'years', true), -1 + (1 / 28.5) / 12, 'Feb 29 2012 to Feb 28 2013 should be 1-(1 / 28.5) / 12 years');
test.done();
}
var moment = require("../../moment");
exports.duration = {
- "object instantiation" : function(test) {
+ "object instantiation" : function (test) {
var d = moment.duration({
years: 2,
months: 3,
test.done();
},
- "milliseconds instantiation" : function(test) {
+ "milliseconds instantiation" : function (test) {
test.expect(1);
test.equal(moment.duration(72).milliseconds(), 72, "milliseconds");
test.done();
},
- "instantiation by type" : function(test) {
+ "instantiation by type" : function (test) {
test.expect(16);
test.equal(moment.duration(1, "years").years(), 1, "years");
test.equal(moment.duration(1, "y").years(), 1, "y");
test.done();
},
- "shortcuts" : function(test) {
+ "shortcuts" : function (test) {
test.expect(8);
test.equal(moment.duration({y: 1}).years(), 1, "years = y");
test.equal(moment.duration({M: 2}).months(), 2, "months = M");
test.done();
},
- "generic getter" : function(test) {
+ "generic getter" : function (test) {
test.expect(24);
test.equal(moment.duration(1, "years").get("years"), 1, "years");
test.equal(moment.duration(1, "years").get("year"), 1, "years = year");
test.done();
},
- "instantiation from another duration" : function(test) {
+ "instantiation from another duration" : function (test) {
var simple = moment.duration(1234),
lengthy = moment.duration(60 * 60 * 24 * 360 * 1e3),
complicated = moment.duration({
test.done();
},
- "instatiation from serialized C# TimeSpan zero" : function(test) {
+ "instatiation from serialized C# TimeSpan zero" : function (test) {
test.expect(6);
test.equal(moment.duration("00:00:00").years(), 0, "0 years");
test.equal(moment.duration("00:00:00").days(), 0, "0 days");
test.done();
},
- "instatiation from serialized C# TimeSpan with days" : function(test) {
+ "instatiation from serialized C# TimeSpan with days" : function (test) {
test.expect(6);
test.equal(moment.duration("1.02:03:04.9999999").years(), 0, "0 years");
test.equal(moment.duration("1.02:03:04.9999999").days(), 1, "1 day");
test.done();
},
- "instatiation from serialized C# TimeSpan without days" : function(test) {
+ "instatiation from serialized C# TimeSpan without days" : function (test) {
test.expect(6);
test.equal(moment.duration("01:02:03.9999999").years(), 0, "0 years");
test.equal(moment.duration("01:02:03.9999999").days(), 0, "0 days");
test.done();
},
- "instatiation from serialized C# TimeSpan without days or milliseconds" : function(test) {
+ "instatiation from serialized C# TimeSpan without days or milliseconds" : function (test) {
test.expect(6);
test.equal(moment.duration("01:02:03").years(), 0, "0 years");
test.equal(moment.duration("01:02:03").days(), 0, "0 days");
test.done();
},
- "instatiation from serialized C# TimeSpan without milliseconds" : function(test) {
+ "instatiation from serialized C# TimeSpan without milliseconds" : function (test) {
test.expect(6);
test.equal(moment.duration("1.02:03:04").years(), 0, "0 years");
test.equal(moment.duration("1.02:03:04").days(), 1, "1 day");
test.done();
},
- "instatiation from serialized C# TimeSpan maxValue" : function(test) {
+ "instatiation from serialized C# TimeSpan maxValue" : function (test) {
test.expect(6);
test.equal(moment.duration("10675199.02:48:05.4775807").years(), 29653, "29653 years");
test.equal(moment.duration("10675199.02:48:05.4775807").days(), 29, "29 day");
test.done();
},
- "instatiation from serialized C# TimeSpan minValue" : function(test) {
+ "instatiation from serialized C# TimeSpan minValue" : function (test) {
test.expect(6);
test.equal(moment.duration("-10675199.02:48:05.4775808").years(), -29653, "29653 years");
test.equal(moment.duration("-10675199.02:48:05.4775808").days(), -29, "29 day");
test.done();
},
- "humanize" : function(test) {
+ "humanize" : function (test) {
test.expect(32);
moment.lang('en');
test.equal(moment.duration({seconds: 44}).humanize(), "a few seconds", "44 seconds = a few seconds");
test.done();
},
- "humanize duration with suffix" : function(test) {
+ "humanize duration with suffix" : function (test) {
test.expect(2);
moment.lang('en');
test.equal(moment.duration({seconds: 44}).humanize(true), "in a few seconds", "44 seconds = a few seconds");
test.done();
},
- "bubble value up" : function(test) {
+ "bubble value up" : function (test) {
test.expect(5);
test.equal(moment.duration({milliseconds: 61001}).milliseconds(), 1, "61001 milliseconds has 1 millisecond left over");
test.equal(moment.duration({milliseconds: 61001}).seconds(), 1, "61001 milliseconds has 1 second left over");
test.done();
},
- "clipping" : function(test) {
+ "clipping" : function (test) {
test.expect(18);
test.equal(moment.duration({months: 11}).months(), 11, "11 months is 11 months");
test.equal(moment.duration({months: 11}).years(), 0, "11 months makes no year");
test.done();
},
- "effective equivalency" : function(test) {
+ "effective equivalency" : function (test) {
test.expect(7);
test.deepEqual(moment.duration({seconds: 1})._data, moment.duration({milliseconds: 1000})._data, "1 second is the same as 1000 milliseconds");
test.deepEqual(moment.duration({seconds: 60})._data, moment.duration({minutes: 1})._data, "1 minute is the same as 60 seconds");
test.done();
},
- "asGetters" : function(test) {
+ "asGetters" : function (test) {
var d = moment.duration({
years: 2,
months: 3,
test.done();
},
- "generic as getter" : function(test) {
+ "generic as getter" : function (test) {
var d = moment.duration({
years: 2,
months: 3,
test.done();
},
- "isDuration" : function(test) {
+ "isDuration" : function (test) {
test.expect(3);
test.ok(moment.isDuration(moment.duration(12345678)), "correctly says true");
test.ok(!moment.isDuration(moment()), "moment object is not a duration");
test.done();
},
- "add" : function(test) {
+ "add" : function (test) {
test.expect(4);
var d = moment.duration({months: 4, weeks: 3, days: 2});
test.equal(d.add(1, 'month')._months, 5, 'Add months');
test.equal(d.add(5, 'days')._days, 28, 'Add days');
test.equal(d.add(10000)._milliseconds, 10000, 'Add milliseconds');
- test.equal(d.add({h: 23, m: 59})._milliseconds, 23*60*60*1000 + 59*60*1000 + 10000, 'Add hour:minute');
+ test.equal(d.add({h: 23, m: 59})._milliseconds, 23 * 60 * 60 * 1000 + 59 * 60 * 1000 + 10000, 'Add hour:minute');
test.done();
},
- "add and bubble" : function(test) {
+ "add and bubble" : function (test) {
test.expect(4);
test.equal(moment.duration(1, 'second').add(1000, 'milliseconds').seconds(), 2, 'Adding milliseconds should bubble up to seconds');
test.done();
},
- "subtract and bubble" : function(test) {
+ "subtract and bubble" : function (test) {
test.expect(4);
test.equal(moment.duration(2, 'second').subtract(1000, 'milliseconds').seconds(), 1, 'Subtracting milliseconds should bubble up to seconds');
test.done();
},
- "subtract" : function(test) {
+ "subtract" : function (test) {
test.expect(4);
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.
test.equal(d.subtract(1, 'months')._months, 1, 'Subtract months');
test.equal(d.subtract(14, 'days')._days, 0, 'Subtract days');
- test.equal(d.subtract(10000)._milliseconds, 5*60*60*1000 - 10000, 'Subtract milliseconds');
- test.equal(d.subtract({h: 1, m: 59})._milliseconds, 3*60*60*1000 + 1*60*1000 - 10000, 'Subtract hour:minute');
+ test.equal(d.subtract(10000)._milliseconds, 5 * 60 * 60 * 1000 - 10000, 'Subtract milliseconds');
+ test.equal(d.subtract({h: 1, m: 59})._milliseconds, 3 * 60 * 60 * 1000 + 1 * 60 * 1000 - 10000, 'Subtract hour:minute');
test.done();
}
var moment = require("../../moment");
exports.format = {
- "format YY" : function(test) {
+ "format YY" : function (test) {
test.expect(1);
var b = moment(new Date(2009, 1, 14, 15, 25, 50, 125));
test.done();
},
- "format escape brackets" : function(test) {
+ "format escape brackets" : function (test) {
test.expect(9);
moment.lang('en');
test.done();
},
- "format milliseconds" : function(test) {
+ "format milliseconds" : function (test) {
test.expect(6);
var b = moment(new Date(2009, 1, 14, 15, 25, 50, 123));
test.equal(b.format('S'), '1', 'Deciseconds');
test.done();
},
- "format timezone" : function(test) {
+ "format timezone" : function (test) {
test.expect(2);
- var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125));
- var explanation = 'moment().format("z") = ' + b.format('z') + ' It should be something like "PST"'
+ var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125)),
+ explanation = 'moment().format("z") = ' + b.format('z') + ' It should be something like "PST"';
if (moment().zone() === -60) {
explanation += "For UTC+1 this is a known issue, see https://github.com/timrwood/moment/issues/162";
}
test.done();
},
- "format multiple with zone" : function(test) {
+ "format multiple with zone" : function (test) {
test.expect(1);
var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']);
test.done();
},
- "isDST" : function(test) {
+ "isDST" : function (test) {
test.expect(2);
var janOffset = new Date(2011, 0, 1).getTimezoneOffset(),
test.done();
},
- "unix timestamp" : function(test) {
+ "unix timestamp" : function (test) {
test.expect(4);
var m = moment('1234567890.123', 'X');
test.done();
},
- "zone" : function(test) {
+ "zone" : function (test) {
test.expect(3);
if (moment().zone() > 0) {
if (moment().zone() < 0) {
test.ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is less than 0, the ISO offset should be greater than zero');
}
- if (moment().zone() == 0) {
+ if (moment().zone() === 0) {
test.ok(moment().format('ZZ').indexOf('+') > -1, 'When the zone() offset is equal to 0, the ISO offset should be positive zero');
}
if (moment().zone() === 0) {
- test.equal(moment().zone(), 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
+ test.equal(moment().zone(), 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
} else {
- test.equal(moment().zone() % 15, 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
+ test.equal(moment().zone() % 15, 0, 'moment.fn.zone should be a multiple of 15 (was ' + moment().zone() + ')');
}
test.equal(moment().zone(), new Date().getTimezoneOffset(), 'zone should equal getTimezoneOffset');
test.done();
},
- "default format" : function(test) {
+ "default format" : function (test) {
test.expect(1);
var isoRegex = /\d{4}.\d\d.\d\dT\d\d.\d\d.\d\d[\+\-]\d\d:\d\d/;
test.ok(isoRegex.exec(moment().format()), "default format (" + moment().format() + ") should match ISO");
test.done();
},
- "escaping quotes" : function(test) {
+ "escaping quotes" : function (test) {
test.expect(4);
moment.lang('en');
var date = moment([2012, 0]);
test.done();
},
- "toJSON" : function(test) {
+ "toJSON" : function (test) {
var supportsJson = typeof JSON !== "undefined" && JSON.stringify && JSON.stringify.call,
date = moment("2012-10-09T21:30:40.678+0100");
test.done();
},
- "toISOString" : function(test) {
+ "toISOString" : function (test) {
var date = moment.utc("2012-10-09T20:30:40.678");
test.equal(date.toISOString(), "2012-10-09T20:30:40.678Z", "should output ISO8601 on moment.fn.toISOString");
test.done();
},
- "weeks format" : function(test) {
+ "weeks format" : function (test) {
// http://en.wikipedia.org/wiki/ISO_week_date
var cases = {
"2010-01-01": "2009-53",
"2010-01-02": "2009-53",
"2010-01-03": "2009-53"
- };
+ }, i, iso, the;
- for (var i in cases) {
- var iso = cases[i].split('-').pop();
- var the = moment(i).format('WW');
+ for (i in cases) {
+ iso = cases[i].split('-').pop();
+ the = moment(i).format('WW');
test.equal(iso, the, i + ": should be " + iso + ", but " + the);
}
test.done();
},
- "iso week year formats" : function(test) {
+ "iso week year formats" : function (test) {
// http://en.wikipedia.org/wiki/ISO_week
var cases = {
"2010-01-01": "2009-53",
"2010-01-02": "2009-53",
"2010-01-03": "2009-53"
- };
+ }, i, isoWeekYear, formatted5, formatted4, formatted2;
- for (var i in cases) {
- var isoWeekYear = cases[i].split('-')[0];
- var formatted5 = moment(i).format('GGGGG');
+ for (i in cases) {
+ isoWeekYear = cases[i].split('-')[0];
+ formatted5 = moment(i).format('GGGGG');
test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted4);
- var formatted4 = moment(i).format('GGGG');
+ formatted4 = moment(i).format('GGGG');
test.equal(isoWeekYear, formatted4, i + ": should be " + isoWeekYear + ", but " + formatted4);
- var formatted2 = moment(i).format('GG');
+ formatted2 = moment(i).format('GG');
test.equal(isoWeekYear.slice(2, 4), formatted2, i + ": should be " + isoWeekYear + ", but " + formatted2);
}
test.done();
},
- "week year formats" : function(test) {
+ "week year formats" : function (test) {
// http://en.wikipedia.org/wiki/ISO_week
var cases = {
"2010-01-01": "2009-53",
"2010-01-02": "2009-53",
"2010-01-03": "2009-53"
- };
+ }, i, formatted5, formatted4, formatted2, isoWeekYear;
moment.lang('en-gb'); // 1, 4
- for (var i in cases) {
- var isoWeekYear = cases[i].split('-')[0];
- var formatted5 = moment(i).format('ggggg');
+ for (i in cases) {
+ isoWeekYear = cases[i].split('-')[0];
+ formatted5 = moment(i).format('ggggg');
test.equal('0' + isoWeekYear, formatted5, i + ": should be " + isoWeekYear + ", but " + formatted4);
- var formatted4 = moment(i).format('gggg');
+ formatted4 = moment(i).format('gggg');
test.equal(isoWeekYear, formatted4, i + ": should be " + isoWeekYear + ", but " + formatted4);
- var formatted2 = moment(i).format('gg');
+ formatted2 = moment(i).format('gg');
test.equal(isoWeekYear.slice(2, 4), formatted2, i + ": should be " + isoWeekYear + ", but " + formatted2);
}
test.done();
},
- "iso weekday formats" : function(test) {
+ "iso weekday formats" : function (test) {
test.expect(7);
test.equal(moment([1985, 1, 4]).format('E'), '1', "Feb 4 1985 is Monday -- 1st day");
test.done();
},
- "weekday formats" : function(test) {
+ "weekday formats" : function (test) {
test.expect(7);
- moment.lang('dow:3,doy:5', {week: {dow: 3, doy: 5}});
+ moment.lang('dow: 3,doy: 5', {week: {dow: 3, doy: 5}});
test.equal(moment([1985, 1, 6]).format('e'), '0', "Feb 6 1985 is Wednesday -- 0th day");
test.equal(moment([2029, 8, 20]).format('e'), '1', "Sep 20 2029 is Thursday -- 1st day");
test.equal(moment([2013, 3, 26]).format('e'), '2', "Apr 26 2013 is Friday -- 2nd day");
test.done();
},
- "toString is just human readable format" : function(test) {
+ "toString is just human readable format" : function (test) {
test.expect(1);
var b = moment(new Date(2009, 1, 5, 15, 25, 50, 125));
test.done();
},
- "toJSON skips postformat" : function(test) {
+ "toJSON skips postformat" : function (test) {
test.expect(1);
- moment.lang('postformat', {postformat: function(s) { s.replace(/./g, 'X') }});
+ moment.lang('postformat', {postformat: function (s) { s.replace(/./g, 'X'); }});
test.equal(moment.utc([2000, 0, 1]).toJSON(), "2000-01-01T00:00:00.000Z", "toJSON doesn't postformat");
test.done();
}
var moment = require("../../moment");
exports.getters_setters = {
- "getters" : function(test) {
+ "getters" : function (test) {
test.expect(8);
var a = moment([2011, 9, 12, 6, 7, 8, 9]);
test.done();
},
- "setters plural" : function(test) {
+ "setters plural" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "setters singular" : function(test) {
+ "setters singular" : function (test) {
test.expect(8);
var a = moment();
test.done();
},
- "setters" : function(test) {
+ "setters" : function (test) {
test.expect(9);
var a = moment();
test.done();
},
- "setters strings" : function(test) {
+ "setters strings" : function (test) {
test.expect(7);
var a = moment([2012]).lang('en');
test.done();
},
- "setters - falsey values" : function(test) {
+ "setters - falsey values" : function (test) {
test.expect(1);
var a = moment();
test.done();
},
- "chaining setters" : function(test) {
+ "chaining setters" : function (test) {
test.expect(7);
var a = moment();
test.done();
},
- "day setter" : function(test) {
+ "day setter" : function (test) {
test.expect(18);
var a = moment([2011, 0, 15]);
var moment = require("../../moment");
exports.is_after = {
- "is after without units" : function(test) {
+ "is after without units" : function (test) {
test.expect(17);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
- test.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, "year is later");
- test.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, "year is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, "month is later");
- test.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, "month is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, "day is later");
- test.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, "day is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, "hour is later");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, "hour is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, "minute is later");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, "minute is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, "second is later");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, "second is earlier");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, "millisecond match");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, "millisecond is later");
- test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, "millisecond is earlier");
+ test.equal(m.isAfter(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, "year is later");
+ test.equal(m.isAfter(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), true, "year is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, "month is later");
+ test.equal(m.isAfter(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), true, "month is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, "day is later");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), true, "day is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, "hour is later");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), true, "hour is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, "minute is later");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), true, "minute is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, "second is later");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), true, "second is earlier");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, "millisecond match");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, "millisecond is later");
+ test.equal(m.isAfter(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), true, "millisecond is earlier");
test.equal(m.isAfter(m), false, "moments are not after themselves");
test.equal(+m, +mCopy, "isAfter second should not change moment");
test.done();
},
- "is after year" : function(test) {
+ "is after year" : function (test) {
test.expect(11);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is after month" : function(test) {
+ "is after month" : function (test) {
test.expect(13);
var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
test.done();
},
- "is after day" : function(test) {
+ "is after day" : function (test) {
test.expect(15);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is after hour" : function(test) {
+ "is after hour" : function (test) {
test.expect(16);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is after minute" : function(test) {
+ "is after minute" : function (test) {
test.expect(18);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is after second" : function(test) {
+ "is after second" : function (test) {
test.expect(20);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
test.done();
},
- "is after millisecond" : function(test) {
+ "is after millisecond" : function (test) {
test.expect(18);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
var moment = require("../../moment");
exports.is_before = {
- "is after without units" : function(test) {
+ "is after without units" : function (test) {
test.expect(17);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
- test.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, "year is later");
- test.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, "year is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, "month is later");
- test.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, "month is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, "day is later");
- test.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, "day is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, "hour is later");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, "hour is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, "minute is later");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, "minute is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, "second is later");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, "second is earlier");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, "millisecond match");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, "millisecond is later");
- test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, "millisecond is earlier");
+ test.equal(m.isBefore(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), true, "year is later");
+ test.equal(m.isBefore(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, "year is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), true, "month is later");
+ test.equal(m.isBefore(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, "month is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), true, "day is later");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, "day is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), true, "hour is later");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, "hour is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), true, "minute is later");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, "minute is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), true, "second is later");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, "second is earlier");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), false, "millisecond match");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), true, "millisecond is later");
+ test.equal(m.isBefore(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, "millisecond is earlier");
test.equal(m.isBefore(m), false, "moments are not before themselves");
test.equal(+m, +mCopy, "isBefore second should not change moment");
test.done();
},
- "is before year" : function(test) {
+ "is before year" : function (test) {
test.expect(11);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is before month" : function(test) {
+ "is before month" : function (test) {
test.expect(13);
var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
test.done();
},
- "is before day" : function(test) {
+ "is before day" : function (test) {
test.expect(15);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is before hour" : function(test) {
+ "is before hour" : function (test) {
test.expect(16);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is before minute" : function(test) {
+ "is before minute" : function (test) {
test.expect(18);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is before second" : function(test) {
+ "is before second" : function (test) {
test.expect(20);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
test.done();
},
- "is before millisecond" : function(test) {
+ "is before millisecond" : function (test) {
test.expect(18);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
var moment = require('../../moment');
exports.is_moment = {
- "is moment object": function(test) {
+ "is moment object": function (test) {
test.expect(11);
- var MyObj = function() {};
- MyObj.prototype.toDate = function() {
+ var MyObj = function () {};
+ MyObj.prototype.toDate = function () {
return new Date();
- }
+ };
test.ok(moment.isMoment(moment()), 'simple moment object');
test.ok(moment.isMoment(moment('invalid date')), 'invalid moment object');
var moment = require("../../moment");
exports.is_same = {
- "is same without units" : function(test) {
+ "is same without units" : function (test) {
test.expect(17);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
- test.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, "year is later");
- test.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, "year is earlier");
- test.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, "month is later");
- test.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, "month is earlier");
- test.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, "day is later");
- test.equal(m.isSame(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, "day is earlier");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, "hour is later");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, "hour is earlier");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, "minute is later");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, "minute is earlier");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, "second is later");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, "second is earlier");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, "millisecond match");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, "millisecond is later");
- test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, "millisecond is earlier");
+ test.equal(m.isSame(moment(new Date(2012, 3, 2, 3, 5, 5, 10))), false, "year is later");
+ test.equal(m.isSame(moment(new Date(2010, 3, 2, 3, 3, 5, 10))), false, "year is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 4, 2, 3, 4, 5, 10))), false, "month is later");
+ test.equal(m.isSame(moment(new Date(2011, 2, 2, 3, 4, 5, 10))), false, "month is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 3, 3, 3, 4, 5, 10))), false, "day is later");
+ test.equal(m.isSame(moment(new Date(2011, 3, 1, 3, 4, 5, 10))), false, "day is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 4, 4, 5, 10))), false, "hour is later");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 2, 4, 5, 10))), false, "hour is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 5, 5, 10))), false, "minute is later");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 3, 5, 10))), false, "minute is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 6, 10))), false, "second is later");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 4, 11))), false, "second is earlier");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 10))), true, "millisecond match");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 11))), false, "millisecond is later");
+ test.equal(m.isSame(moment(new Date(2011, 3, 2, 3, 4, 5, 9))), false, "millisecond is earlier");
test.equal(m.isSame(m), true, "moments are the same as themselves");
test.equal(+m, +mCopy, "isSame second should not change moment");
test.done();
},
- "is same year" : function(test) {
+ "is same year" : function (test) {
test.expect(9);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is same month" : function(test) {
+ "is same month" : function (test) {
test.expect(10);
var m = moment(new Date(2011, 2, 3, 4, 5, 6, 7)), mCopy = moment(m);
test.done();
},
- "is same day" : function(test) {
+ "is same day" : function (test) {
test.expect(11);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is same hour" : function(test) {
+ "is same hour" : function (test) {
test.expect(12);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is same minute" : function(test) {
+ "is same minute" : function (test) {
test.expect(13);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is same second" : function(test) {
+ "is same second" : function (test) {
test.expect(14);
var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)), mCopy = moment(m);
test.done();
},
- "is same millisecond" : function(test) {
+ "is same millisecond" : function (test) {
test.expect(18);
var m = moment(new Date(2011, 3, 2, 3, 4, 5, 10)), mCopy = moment(m);
'2010-01-01T24',
'2010-01-01T23:60',
'2010-01-01T23:59:60'
- ];
+ ], i;
test.expect(tests.length * 2);
- for (var i = 0; i < tests.length; i++) {
+ for (i = 0; i < tests.length; i++) {
test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
}
'2010-01-40T23:60+00:00',
'2010-01-40T23:59:60+00:00',
'2010-01-40T23:59:59.9999+00:00'
- ];
+ ], i;
test.expect(tests.length * 2);
- for (var i = 0; i < tests.length; i++) {
+ for (i = 0; i < tests.length; i++) {
test.equal(moment(tests[i]).isValid(), false, tests[i] + ' should be invalid');
test.equal(moment.utc(tests[i]).isValid(), false, tests[i] + ' should be invalid');
}
'2010-01-30T23:59:59.999+00:00',
'2010-01-30T23:59:59.999-07:00',
'2010-01-30T00:00:00.000+07:00'
- ];
+ ], i;
test.expect(tests.length * 2);
- for (var i = 0; i < tests.length; i++) {
+ for (i = 0; i < tests.length; i++) {
test.equal(moment(tests[i]).isValid(), true, tests[i] + ' should be valid');
test.equal(moment.utc(tests[i]).isValid(), true, tests[i] + ' should be valid');
}
var moment = require("../../moment");
exports.leapyear = {
- "leap year" : function(test) {
+ "leap year" : function (test) {
test.expect(4);
test.equal(moment([2010, 0, 1]).isLeapYear(), false, '2010');
"manipulation methods" : function (test) {
var mutableMethods = {
- 'year': function (m){ return m.year(2011); },
- 'month': function (m){ return m.month(1); },
- 'date': function (m){ return m.date(9); },
- 'hours': function (m){ return m.hours(7); },
- 'minutes': function (m){ return m.minutes(33); },
- 'seconds': function (m){ return m.seconds(44); },
- 'milliseconds': function (m){ return m.milliseconds(55); },
- 'day': function (m){ return m.day(2); },
- 'startOf': function (m){ return m.startOf('week') },
- 'endOf': function (m){ return m.endOf('week') },
- 'add': function (m){ return m.add('days', 1) },
- 'subtract': function (m){ return m.subtract('years', 2) },
- 'local': function (m){ return m.local() },
- 'utc': function (m){ return m.utc() }
- };
+ 'year': function (m) { return m.year(2011); },
+ 'month': function (m) { return m.month(1); },
+ 'date': function (m) { return m.date(9); },
+ 'hours': function (m) { return m.hours(7); },
+ 'minutes': function (m) { return m.minutes(33); },
+ 'seconds': function (m) { return m.seconds(44); },
+ 'milliseconds': function (m) { return m.milliseconds(55); },
+ 'day': function (m) { return m.day(2); },
+ 'startOf': function (m) { return m.startOf('week'); },
+ 'endOf': function (m) { return m.endOf('week'); },
+ 'add': function (m) { return m.add('days', 1); },
+ 'subtract': function (m) { return m.subtract('years', 2); },
+ 'local': function (m) { return m.local(); },
+ 'utc': function (m) { return m.utc(); }
+ }, method, d, d2;
test.expect(14);
for (method in mutableMethods) {
if (mutableMethods.hasOwnProperty(method)) {
- var d = moment();
- var d2 = mutableMethods[method](d);
+ d = moment();
+ d2 = mutableMethods[method](d);
test.equal(d, d2, method + "() should be mutable");
}
}
"non mutable methods" : function (test) {
var nonMutableMethods = {
- 'clone': function (m){ return m.clone() }
- };
+ 'clone': function (m) { return m.clone(); }
+ }, method, d, d2;
test.expect(1);
- for (method in nonMutableMethods){
+ for (method in nonMutableMethods) {
if (nonMutableMethods.hasOwnProperty(method)) {
- var d = new Date();
- var d2 = nonMutableMethods[method](moment(d)).toDate();
+ d = new Date();
+ d2 = nonMutableMethods[method](moment(d)).toDate();
test.notEqual(d, d2, method + "() should not be mutable");
}
}
var symbolMap = {
- '1': '!',
- '2': '@',
- '3': '#',
- '4': '$',
- '5': '%',
- '6': '^',
- '7': '&',
- '8': '*',
- '9': '(',
- '0': ')'
+ '1': '!',
+ '2': '@',
+ '3': '#',
+ '4': '$',
+ '5': '%',
+ '6': '^',
+ '7': '&',
+ '8': '*',
+ '9': '(',
+ '0': ')'
};
var numberMap = {
- '!': '1',
- '@': '2',
- '#': '3',
- '$': '4',
- '%': '5',
- '^': '6',
- '&': '7',
- '*': '8',
- '(': '9',
- ')': '0'
+ '!': '1',
+ '@': '2',
+ '#': '3',
+ '$': '4',
+ '%': '5',
+ '^': '6',
+ '&': '7',
+ '*': '8',
+ '(': '9',
+ ')': '0'
};
var symbolLang = {
- preparse: function(string) {
- return string.replace(/[!@#$%\^&*()]/g, function(match) {
+ preparse: function (string) {
+ return string.replace(/[!@#$%\^&*()]/g, function (match) {
return numberMap[match];
});
},
- postformat: function(string) {
- return string.replace(/\d/g, function(match) {
+ postformat: function (string) {
+ return string.replace(/\d/g, function (match) {
return symbolMap[match];
});
}
};
exports.preparse_postformat = {
- setUp: function(cb) {
+ setUp: function (cb) {
moment.lang('symbol', symbolLang);
cb();
},
- tearDown: function(cb) {
+ tearDown: function (cb) {
moment.lang('en-gb');
cb();
},
- "transform": function(test) {
+ "transform": function (test) {
test.expect(3);
test.equal(moment.utc('@)!@-)*-@&', 'YYYY-MM-DD').unix(), 1346025600, "preparse string + format");
test.done();
},
- "transform from": function(test) {
+ "transform from": function (test) {
test.expect(3);
var start = moment([2007, 1, 28]);
- test.equal(start.from(moment([2007, 1, 28]).add({s:90}), true), "@ minutes", "postformat should work on moment.fn.from");
+ test.equal(start.from(moment([2007, 1, 28]).add({s: 90}), true), "@ minutes", "postformat should work on moment.fn.from");
test.equal(moment().add('d', 6).fromNow(true), "^ days", "postformat should work on moment.fn.fromNow");
test.equal(moment.duration(10, "h").humanize(), "!) hours", "postformat should work on moment.duration.fn.humanize");
test.done();
},
- "calendar day" : function(test) {
+ "calendar day" : function (test) {
test.expect(6);
var a = moment().hours(2).minutes(0).seconds(0);
cb();
},
- "start of year" : function(test) {
+ "start of year" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('year');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('years');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('y');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('year'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('years'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('y');
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.done();
},
- "end of year" : function(test) {
+ "end of year" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('year');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('years');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('y');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('year'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('years'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('y');
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.done();
},
- "start of month" : function(test) {
+ "start of month" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('month');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('months');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('M');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('month'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('months'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('M');
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.done();
},
- "end of month" : function(test) {
+ "end of month" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('month');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('months');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('M');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('month'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('months'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('M');
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.done();
},
- "start of week" : function(test) {
+ "start of week" : function (test) {
test.expect(10);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('week');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('weeks');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('w');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('week'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('weeks'),
+ 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.done();
},
- "end of week" : function(test) {
+ "end of week" : function (test) {
test.expect(10);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('week');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('week'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('weeks');
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.done();
},
- "start of day" : function(test) {
+ "start of day" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('day');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('days');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('d');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('day'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('days'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('d');
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.done();
},
- "end of day" : function(test) {
+ "end of day" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('day');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('days');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('d');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('day'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('days'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('d');
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.done();
},
- "start of hour" : function(test) {
+ "start of hour" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hour');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hours');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('h');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hour'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('hours'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('h');
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.done();
},
- "end of hour" : function(test) {
+ "end of hour" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hour');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hours');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('h');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hour'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('hours'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('h');
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.done();
},
- "start of minute" : function(test) {
+ "start of minute" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minute');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minutes');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('m');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minute'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('minutes'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('m');
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.done();
},
- "end of minute" : function(test) {
+ "end of minute" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minute');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minutes');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('m');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minute'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('minutes'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('m');
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.done();
},
- "start of second" : function(test) {
+ "start of second" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('second');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('seconds');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('s');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('second'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('seconds'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).startOf('s');
test.equal(+m, +ms, "Plural or singular should work");
- test.equal(+m, +ma, "Full or abbreviated 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.date(), 2, "keep the day");
test.done();
},
- "end of second" : function(test) {
+ "end of second" : function (test) {
test.expect(9);
- var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('second');
- var ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('seconds');
- var ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('s');
+ var m = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('second'),
+ ms = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('seconds'),
+ ma = moment(new Date(2011, 1, 2, 3, 4, 5, 6)).endOf('s');
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");
var moment = require("../../moment");
exports.add = {
- "string prototype overrides call" : function(test) {
+ "string prototype overrides call" : function (test) {
test.expect(1);
- var prior = String.prototype.call;
- String.prototype.call = function() { return null;};
+ var prior = String.prototype.call, b;
+ String.prototype.call = function () { return null; };
- var b = moment(new Date(2011, 7, 28, 15, 25, 50, 125));
+ b = moment(new Date(2011, 7, 28, 15, 25, 50, 125));
test.equal(b.format('MMMM Do YYYY, h:mm a'), 'August 28th 2011, 3:25 pm');
String.prototype.call = prior;
cb();
},
- "utc and local" : function(test) {
+ "utc and local" : function (test) {
test.expect(7);
- var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6));
+ var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), zone, expected;
m.utc();
// utc
test.equal(m.date(), 2, "the day should be correct for utc");
test.equal(m.date(), 2, "the date should be correct for local");
test.equal(m.day(), 3, "the day should be correct for local");
}
- var zone = Math.ceil(m.zone() / 60);
- var expected = (24 + 3 - zone) % 24;
+ zone = Math.ceil(m.zone() / 60);
+ expected = (24 + 3 - zone) % 24;
test.equal(m.hours(), expected, "the hours (" + m.hours() + ") should be correct for local");
test.equal(moment().utc().zone(), 0, "timezone in utc should always be zero");
test.done();
},
- "creating with utc" : function(test) {
+ "creating with utc" : function (test) {
test.expect(7);
- var diff = moment.utc().valueOf() - moment().valueOf();
+ var diff = moment.utc().valueOf() - moment().valueOf(), m;
diff = Math.abs(diff);
// we check the diff rather than equality because sometimes they are off by a millisecond
test.ok(diff < 5, "Calling moment.utc() should default to the current time");
- var m = moment.utc([2011, 1, 2, 3, 4, 5, 6]);
+ m = moment.utc([2011, 1, 2, 3, 4, 5, 6]);
test.equal(m.date(), 2, "the day should be correct for utc array");
test.equal(m.hours(), 3, "the hours should be correct for utc array");
test.done();
},
- "creating with utc without timezone" : function(test) {
+ "creating with utc without timezone" : function (test) {
test.expect(4);
var m = moment.utc("2012-01-02T08:20:00");
var moment = require("../../moment");
exports.week_year = {
- "iso week year": function(test) {
+ "iso week year": function (test) {
test.expect(19);
// Some examples taken from http://en.wikipedia.org/wiki/ISO_week
test.done();
},
- "week year": function(test) {
+ "week year": function (test) {
test.expect(31);
// Some examples taken from http://en.wikipedia.org/wiki/ISO_week
- moment.lang('dow:1,doy:4', {week: {dow: 1, doy: 4}}); // like iso
+ moment.lang('dow: 1,doy: 4', {week: {dow: 1, doy: 4}}); // like iso
test.equal(moment([2005, 0, 1]).weekYear(), 2004);
test.equal(moment([2005, 0, 2]).weekYear(), 2004);
test.equal(moment([2005, 0, 3]).weekYear(), 2005);
test.equal(moment([2010, 0, 3]).weekYear(), 2009);
test.equal(moment([2010, 0, 4]).weekYear(), 2010);
- moment.lang('dow:1,doy:7', {week: {dow: 1, doy: 7}});
+ moment.lang('dow: 1,doy: 7', {week: {dow: 1, doy: 7}});
test.equal(moment([2004, 11, 26]).weekYear(), 2004);
test.equal(moment([2004, 11, 27]).weekYear(), 2005);
test.equal(moment([2005, 11, 25]).weekYear(), 2005);
var moment = require("../../moment");
exports.week_year = {
- "iso weekday": function(test) {
+ "iso weekday": function (test) {
var i;
test.expect(7 * 7);
for (i = 0; i < 7; ++i) {
- moment.lang('dow:' + i + ',doy:6', {week: {dow: i, doy: 6}});
+ moment.lang('dow:' + i + ',doy: 6', {week: {dow: i, doy: 6}});
test.equal(moment([1985, 1, 4]).isoWeekday(), 1, "Feb 4 1985 is Monday -- 1st day");
test.equal(moment([2029, 8, 18]).isoWeekday(), 2, "Sep 18 2029 is Tuesday -- 2nd day");
test.equal(moment([2013, 3, 24]).isoWeekday(), 3, "Apr 24 2013 is Wednesday -- 3rd day");
test.done();
},
- "iso weekday setter" : function(test) {
+ "iso weekday setter" : function (test) {
test.expect(27);
var a = moment([2011, 0, 10]);
test.done();
},
- "weekday first day of week Sunday (dow 0)": function(test) {
+ "weekday first day of week Sunday (dow 0)": function (test) {
test.expect(7);
- moment.lang('dow:0,doy:6', {week: {dow: 0, doy: 6}});
+ moment.lang('dow: 0,doy: 6', {week: {dow: 0, doy: 6}});
test.equal(moment([1985, 1, 3]).weekday(), 0, "Feb 3 1985 is Sunday -- 0th day");
test.equal(moment([2029, 8, 17]).weekday(), 1, "Sep 17 2029 is Monday -- 1st day");
test.equal(moment([2013, 3, 23]).weekday(), 2, "Apr 23 2013 is Tuesday -- 2nd day");
test.done();
},
- "weekday first day of week Monday (dow 1)": function(test) {
+ "weekday first day of week Monday (dow 1)": function (test) {
test.expect(7);
- moment.lang('dow:1,doy:6', {week: {dow: 1, doy: 6}});
+ moment.lang('dow: 1,doy: 6', {week: {dow: 1, doy: 6}});
test.equal(moment([1985, 1, 4]).weekday(), 0, "Feb 4 1985 is Monday -- 0th day");
test.equal(moment([2029, 8, 18]).weekday(), 1, "Sep 18 2029 is Tuesday -- 1st day");
test.equal(moment([2013, 3, 24]).weekday(), 2, "Apr 24 2013 is Wednesday -- 2nd day");
test.done();
},
- "weekday first day of week Tuesday (dow 2)": function(test) {
+ "weekday first day of week Tuesday (dow 2)": function (test) {
test.expect(7);
- moment.lang('dow:2,doy:6', {week: {dow: 2, doy: 6}});
+ moment.lang('dow: 2,doy: 6', {week: {dow: 2, doy: 6}});
test.equal(moment([1985, 1, 5]).weekday(), 0, "Feb 5 1985 is Tuesday -- 0th day");
test.equal(moment([2029, 8, 19]).weekday(), 1, "Sep 19 2029 is Wednesday -- 1st day");
test.equal(moment([2013, 3, 25]).weekday(), 2, "Apr 25 2013 is Thursday -- 2nd day");
test.done();
},
- "weekday first day of week Wednesday (dow 3)": function(test) {
+ "weekday first day of week Wednesday (dow 3)": function (test) {
test.expect(7);
- moment.lang('dow:3,doy:6', {week: {dow: 3, doy: 6}});
+ moment.lang('dow: 3,doy: 6', {week: {dow: 3, doy: 6}});
test.equal(moment([1985, 1, 6]).weekday(), 0, "Feb 6 1985 is Wednesday -- 0th day");
test.equal(moment([2029, 8, 20]).weekday(), 1, "Sep 20 2029 is Thursday -- 1st day");
test.equal(moment([2013, 3, 26]).weekday(), 2, "Apr 26 2013 is Friday -- 2nd day");
test.done();
},
- "weekday first day of week Thursday (dow 4)": function(test) {
+ "weekday first day of week Thursday (dow 4)": function (test) {
test.expect(7);
- moment.lang('dow:4,doy:6', {week: {dow: 4, doy: 6}});
+ moment.lang('dow: 4,doy: 6', {week: {dow: 4, doy: 6}});
test.equal(moment([1985, 1, 7]).weekday(), 0, "Feb 7 1985 is Thursday -- 0th day");
test.equal(moment([2029, 8, 21]).weekday(), 1, "Sep 21 2029 is Friday -- 1st day");
test.done();
},
- "weekday first day of week Friday (dow 5)": function(test) {
+ "weekday first day of week Friday (dow 5)": function (test) {
test.expect(7);
- moment.lang('dow:5,doy:6', {week: {dow: 5, doy: 6}});
+ moment.lang('dow: 5,doy: 6', {week: {dow: 5, doy: 6}});
test.equal(moment([1985, 1, 8]).weekday(), 0, "Feb 8 1985 is Friday -- 0th day");
test.equal(moment([2029, 8, 22]).weekday(), 1, "Sep 22 2029 is Staturday -- 1st day");
test.equal(moment([2013, 3, 28]).weekday(), 2, "Apr 28 2013 is Sunday -- 2nd day");
test.done();
},
- "weekday first day of week Saturday (dow 6)": function(test) {
+ "weekday first day of week Saturday (dow 6)": function (test) {
test.expect(7);
- moment.lang('dow:6,doy:6', {week: {dow: 6, doy: 6}});
+ moment.lang('dow: 6,doy: 6', {week: {dow: 6, doy: 6}});
test.equal(moment([1985, 1, 9]).weekday(), 0, "Feb 9 1985 is Staturday -- 0th day");
test.equal(moment([2029, 8, 23]).weekday(), 1, "Sep 23 2029 is Sunday -- 1st day");
test.equal(moment([2013, 3, 29]).weekday(), 2, "Apr 29 2013 is Monday -- 2nd day");
test.equal(moment([2000, 1, 28]).dayOfYear(200).dayOfYear(), 200, "Setting Feb 28 2000 day of the year to 200 should work");
test.equal(moment([2000, 1, 29]).dayOfYear(200).dayOfYear(), 200, "Setting Feb 28 2000 day of the year to 200 should work");
test.equal(moment([2000, 11, 31]).dayOfYear(200).dayOfYear(), 200, "Setting Dec 31 2000 day of the year to 200 should work");
- test.equal(moment().dayOfYear( 1).dayOfYear(), 1, "Setting day of the year to 1 should work");
- test.equal(moment().dayOfYear( 59).dayOfYear(), 59, "Setting day of the year to 59 should work");
- test.equal(moment().dayOfYear( 60).dayOfYear(), 60, "Setting day of the year to 60 should work");
+ test.equal(moment().dayOfYear(1).dayOfYear(), 1, "Setting day of the year to 1 should work");
+ test.equal(moment().dayOfYear(59).dayOfYear(), 59, "Setting day of the year to 59 should work");
+ test.equal(moment().dayOfYear(60).dayOfYear(), 60, "Setting day of the year to 60 should work");
test.equal(moment().dayOfYear(365).dayOfYear(), 365, "Setting day of the year to 365 should work");
test.done();
},
- "iso weeks year starting sunday" : function(test) {
+ "iso weeks year starting sunday" : function (test) {
test.expect(5);
test.equal(moment([2012, 0, 1]).isoWeek(), 52, "Jan 1 2012 should be iso week 52");
test.done();
},
- "iso weeks year starting monday" : function(test) {
+ "iso weeks year starting monday" : function (test) {
test.expect(5);
test.equal(moment([2007, 0, 1]).isoWeek(), 1, "Jan 1 2007 should be iso week 1");
test.done();
},
- "iso weeks year starting tuesday" : function(test) {
+ "iso weeks year starting tuesday" : function (test) {
test.expect(6);
test.equal(moment([2007, 11, 31]).isoWeek(), 1, "Dec 31 2007 should be iso week 1");
test.done();
},
- "iso weeks year starting wednesday" : function(test) {
+ "iso weeks year starting wednesday" : function (test) {
test.expect(6);
test.equal(moment([2002, 11, 30]).isoWeek(), 1, "Dec 30 2002 should be iso week 1");
test.done();
},
- "iso weeks year starting thursday" : function(test) {
+ "iso weeks year starting thursday" : function (test) {
test.expect(6);
test.equal(moment([2008, 11, 29]).isoWeek(), 1, "Dec 29 2008 should be iso week 1");
test.done();
},
- "iso weeks year starting friday" : function(test) {
+ "iso weeks year starting friday" : function (test) {
test.expect(6);
test.equal(moment([2009, 11, 28]).isoWeek(), 53, "Dec 28 2009 should be iso week 53");
test.done();
},
- "iso weeks year starting saturday" : function(test) {
+ "iso weeks year starting saturday" : function (test) {
test.expect(6);
test.equal(moment([2010, 11, 27]).isoWeek(), 52, "Dec 27 2010 should be iso week 52");
test.done();
},
- "iso weeks year starting sunday formatted" : function(test) {
+ "iso weeks year starting sunday formatted" : function (test) {
test.expect(5);
test.equal(moment([2012, 0, 1]).format('W WW Wo'), '52 52 52nd', "Jan 1 2012 should be iso week 52");
- test.equal(moment([2012, 0, 2]).format('W WW Wo'), '1 01 1st' , "Jan 2 2012 should be iso week 1");
- test.equal(moment([2012, 0, 8]).format('W WW Wo'), '1 01 1st' , "Jan 8 2012 should be iso week 1");
- 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.equal(moment([2012, 0, 2]).format('W WW Wo'), '1 01 1st', "Jan 2 2012 should be iso week 1");
+ test.equal(moment([2012, 0, 8]).format('W WW Wo'), '1 01 1st', "Jan 8 2012 should be iso week 1");
+ 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) {
+ "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.done();
},
- "iso weeks plural year starting sunday" : function(test) {
+ "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.done();
},
- "weeks setter" : function(test) {
+ "weeks setter" : function (test) {
test.expect(5);
test.equal(moment([2012, 0, 1]).week(30).week(), 30, "Setting Jan 1 2012 to week 30 should work");
test.done();
},
- "iso weeks setter" : function(test) {
+ "iso weeks setter" : function (test) {
test.expect(5);
test.equal(moment([2012, 0, 1]).isoWeeks(25).isoWeeks(), 25, "Setting Jan 1 2012 to week 25 should work");
test.done();
},
- "iso weeks setter day of year" : function(test) {
+ "iso weeks setter day of year" : function (test) {
test.expect(6);
test.equal(moment([2012, 0, 1]).isoWeek(1).dayOfYear(), 9, "Setting Jan 1 2012 to week 1 should be day of year 8");