Skip to content

Instantly share code, notes, and snippets.

@camsong
Forked from timrwood/moment-immutable.js
Created October 25, 2015 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camsong/401932916a9925d21576 to your computer and use it in GitHub Desktop.
Save camsong/401932916a9925d21576 to your computer and use it in GitHub Desktop.
Immutable Moments
(function (root, factory) {
"use strict";
if (typeof define === 'function' && define.amd) {
define(['moment'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('moment'));
} else {
factory(root.moment);
}
}(this, function (moment) {
"use strict";
function wrap (name) {
var old = moment.fn[name];
moment.fn[name] = function () {
return old.apply(this.clone(), arguments);
};
}
var methods = 'add subtract startOf endOf'.split(' ');
for (var i = 0; i < methods.length; i++) {
wrap(methods[i]);
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment