diff options
Diffstat (limited to 'library/moment/src/lib/moment/compare.js')
-rw-r--r-- | library/moment/src/lib/moment/compare.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/library/moment/src/lib/moment/compare.js b/library/moment/src/lib/moment/compare.js new file mode 100644 index 000000000..b6634737a --- /dev/null +++ b/library/moment/src/lib/moment/compare.js @@ -0,0 +1,43 @@ +import { isMoment } from './constructor'; +import { normalizeUnits } from '../units/aliases'; +import { createLocal } from '../create/local'; + +export function isAfter (input, units) { + var inputMs; + units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); + if (units === 'millisecond') { + input = isMoment(input) ? input : createLocal(input); + return +this > +input; + } else { + inputMs = isMoment(input) ? +input : +createLocal(input); + return inputMs < +this.clone().startOf(units); + } +} + +export function isBefore (input, units) { + var inputMs; + units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond'); + if (units === 'millisecond') { + input = isMoment(input) ? input : createLocal(input); + return +this < +input; + } else { + inputMs = isMoment(input) ? +input : +createLocal(input); + return +this.clone().endOf(units) < inputMs; + } +} + +export function isBetween (from, to, units) { + return this.isAfter(from, units) && this.isBefore(to, units); +} + +export function isSame (input, units) { + var inputMs; + units = normalizeUnits(units || 'millisecond'); + if (units === 'millisecond') { + input = isMoment(input) ? input : createLocal(input); + return +this === +input; + } else { + inputMs = +createLocal(input); + return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units)); + } +} |