Skip to content

Instantly share code, notes, and snippets.

@lorenzoongithub
Created June 7, 2015 20:42
Show Gist options
  • Save lorenzoongithub/f902b1dcbe298738356b to your computer and use it in GitHub Desktop.
Save lorenzoongithub/f902b1dcbe298738356b to your computer and use it in GitHub Desktop.
moment.js
//
// momentjs.com -
//
load('http://momentjs.com/static/js/global.js');
//
// add short reverse args
//
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);
if (a.add({ms: 50}).milliseconds() !== 550) throw ''
if (a.add({s: 1}).seconds() !== 9) throw ''
if (a.add({m: 1}).minutes() !== 8) throw ''
if (a.add({h: 1}).hours() !== 7) throw ''
if (a.add({d: 1}).date() !== 13) throw ''
if (a.add({w: 1}).date() !== 20) throw ''
if (a.add({M: 1}).month() !== 10) throw ''
if (a.add({y: 1}).year() !== 2012) throw ''
if (a.add({Q: 1}).month() !== 1) throw ''
b = moment([2010, 0, 31]).add({M: 1});
c = moment([2010, 1, 28]).subtract({M: 1});
d = moment([2010, 1, 28]).subtract({Q: 1});
if (b.month() !== 1) throw ''
if (b.date() !== 28) throw ''
if (c.month() !== 0) throw ''
if (c.date() !== 28) throw ''
if (d.month() !== 10) throw ''
if (d.date() !== 28) throw ''
if (d.year() !== 2009) throw ''
//
// add long reverse args
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add({milliseconds: 50}).milliseconds() !== 550) throw ''
if (a.add({seconds: 1}).seconds() !== 9) throw ''
if (a.add({minutes: 1}).minutes() !== 8) throw ''
if (a.add({hours: 1}).hours() !== 7) throw ''
if (a.add({days: 1}).date() !== 13) throw ''
if (a.add({weeks: 1}).date() !== 20) throw ''
if (a.add({months: 1}).month() !== 10) throw ''
if (a.add({years: 1}).year() !== 2012) throw ''
if (a.add({quarters: 1}).month() !== 1) throw ''
//
// add long singular reverse args
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add({millisecond: 50}).milliseconds() !== 550) throw ''
if (a.add({second: 1}).seconds() !== 9) throw ''
if (a.add({minute: 1}).minutes() !== 8) throw ''
if (a.add({hour: 1}).hours() !== 7) throw ''
if (a.add({day: 1}).date() !== 13) throw ''
if (a.add({week: 1}).date() !== 20) throw ''
if (a.add({month: 1}).month() !== 10) throw ''
if (a.add({year: 1}).year() !== 2012) throw ''
if (a.add({quarter: 1}).month() !== 1) throw ''
//
// add string long reverse args
//
var a = moment(), b;
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
b = a.clone();
if (a.add('millisecond', 50).milliseconds() !== 550) throw ''
if (a.add('second', 1).seconds() !== 9) throw ''
if (a.add('minute', 1).minutes() !== 8) throw ''
if (a.add('hour', 1).hours() !== 7) throw ''
if (a.add('day', 1).date() !== 13) throw ''
if (a.add('week', 1).date() !== 20) throw ''
if (a.add('month', 1).month() !== 10) throw ''
if (a.add('year', 1).year() !== 2012) throw ''
if (b.add('day', '01').date() !== 13) throw ''
if (a.add('quarter', 1).month() !== 1) throw ''
//
// add string long singular reverse args
//
var a = moment(), b;
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
b = a.clone();
if (a.add('milliseconds', 50).milliseconds() !== 550) throw ''
if (a.add('seconds', 1).seconds() !== 9) throw ''
if (a.add('minutes', 1).minutes() !== 8) throw ''
if (a.add('hours', 1).hours() !== 7) throw ''
if (a.add('days', 1).date() !== 13) throw ''
if (a.add('weeks', 1).date() !== 20) throw ''
if (a.add('months', 1).month() !== 10) throw ''
if (a.add('years', 1).year() !== 2012) throw ''
if (b.add('days', '01').date() !== 13) throw ''
if (a.add('quarters', 1).month() !== 1) throw ''
//
// add string short reverse args
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add('ms', 50).milliseconds() !== 550) throw ''
if (a.add('s', 1).seconds() !== 9) throw ''
if (a.add('m', 1).minutes() !== 8) throw ''
if (a.add('h', 1).hours() !== 7) throw ''
if (a.add('d', 1).date() !== 13) throw ''
if (a.add('w', 1).date() !== 20) throw ''
if (a.add('M', 1).month() !== 10) throw ''
if (a.add('y', 1).year() !== 2012) throw ''
if (a.add('Q', 1).month() !== 1) throw ''
//
// add string long
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add(50, 'millisecond').milliseconds() !== 550) throw ''
if (a.add(1, 'second').seconds() !== 9) throw ''
if (a.add(1, 'minute').minutes() !== 8) throw ''
if (a.add(1, 'hour').hours() !== 7) throw ''
if (a.add(1, 'day').date() !== 13) throw ''
if (a.add(1, 'week').date() !== 20) throw ''
if (a.add(1, 'month').month() !== 10) throw ''
if (a.add(1, 'year').year() !== 2012) throw ''
if (a.add(1, 'quarter').month() !== 1) throw ''
//
// add string long singular
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add(50, 'milliseconds').milliseconds() !== 550) throw ''
if (a.add(1, 'seconds').seconds() !== 9) throw ''
if (a.add(1, 'minutes').minutes() !== 8) throw ''
if (a.add(1, 'hours').hours() !== 7) throw ''
if (a.add(1, 'days').date() !== 13) throw ''
if (a.add(1, 'weeks').date() !== 20) throw ''
if (a.add(1, 'months').month() !== 10) throw ''
if (a.add(1, 'years').year() !== 2012) throw ''
if (a.add(1, 'quarters').month() !== 1) throw ''
//
// add string short
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add(50, 'ms').milliseconds() !== 550) throw ''
if (a.add(1, 's').seconds() !== 9) throw ''
if (a.add(1, 'm').minutes() !== 8) throw ''
if (a.add(1, 'h').hours() !== 7) throw ''
if (a.add(1, 'd').date() !== 13) throw ''
if (a.add(1, 'w').date() !== 20) throw ''
if (a.add(1, 'M').month() !== 10) throw ''
if (a.add(1, 'y').year() !== 2012) throw ''
if (a.add(1, 'Q').month() !== 1) throw ''
//
// add strings string short args
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add('ms', '50').milliseconds() !== 550) throw ''
if (a.add('s', '1').seconds() !== 9) throw ''
if (a.add('m', '1').minutes() !== 8) throw ''
if (a.add('h', '1').hours() !== 7) throw ''
if (a.add('d', '1').date() !== 13) throw ''
if (a.add('w', '1').date() !== 20) throw ''
if (a.add('M', '1').month() !== 10) throw ''
if (a.add('y', '1').year() !== 2012) throw ''
if (a.add('Q', '1').month() !== 1) throw ''
//
// subtract strings string short args
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.subtract('ms', '50').milliseconds() !== 450) throw ''
if (a.subtract('s', '1').seconds() !== 7) throw ''
if (a.subtract('m', '1').minutes() !== 6) throw ''
if (a.subtract('h', '1').hours() !== 5) throw ''
if (a.subtract('d', '1').date() !== 11) throw ''
if (a.subtract('w', '1').date() !== 4) throw ''
if (a.subtract('M', '1').month() !== 8) throw ''
if (a.subtract('y', '1').year() !== 2010) throw ''
if (a.subtract('Q', '1').month() !== 5) throw ''
//
// add strings string short
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.add('50', 'ms').milliseconds() !== 550) throw ''
if (a.add('1', 's').seconds() !== 9) throw ''
if (a.add('1', 'm').minutes() !== 8) throw ''
if (a.add('1', 'h').hours() !== 7) throw ''
if (a.add('1', 'd').date() !== 13) throw ''
if (a.add('1', 'w').date() !== 20) throw ''
if (a.add('1', 'M').month() !== 10) throw ''
if (a.add('1', 'y').year() !== 2012) throw ''
if (a.add('1', 'Q').month() !== 1) throw ''
//
// subtract strings string short
//
var a = moment();
a.year(2011);
a.month(9);
a.date(12);
a.hours(6);
a.minutes(7);
a.seconds(8);
a.milliseconds(500);
if (a.subtract('50', 'ms').milliseconds() !== 450) throw ''
if (a.subtract('1', 's').seconds() !== 7) throw ''
if (a.subtract('1', 'm').minutes() !== 6) throw ''
if (a.subtract('1', 'h').hours() !== 5) throw ''
if (a.subtract('1', 'd').date() !== 11) throw ''
if (a.subtract('1', 'w').date() !== 4) throw ''
if (a.subtract('1', 'M').month() !== 8) throw ''
if (a.subtract('1', 'y').year() !== 2010) throw ''
if (a.subtract('1', 'Q').month() !== 5) throw ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment