Last active
August 29, 2015 14:00
-
-
Save netsensei/13234d4f4612a127f886 to your computer and use it in GitHub Desktop.
Extends moment.js with isBeforeOrSame or isAfterOrSame methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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