Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save netsensei/13234d4f4612a127f886 to your computer and use it in GitHub Desktop.
Save netsensei/13234d4f4612a127f886 to your computer and use it in GitHub Desktop.
Extends moment.js with isBeforeOrSame or isAfterOrSame methods.
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['moment'], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory(require('moment'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.moment);
}
}(this, function (moment) {
'use strict';
moment.fn.isBeforeOrSame = function (input, units) {
units = typeof units !== 'undefined' ? units : 'millisecond';
return +this.clone().startOf(units) <= +moment(input).startOf(units);
}
moment.fn.isAfterOrSame = function (input, units) {
units = typeof units !== 'undefined' ? units : 'millisecond';
return +this.clone().startOf(units) >= +moment(input).startOf(units);
}
return moment;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment