PageRenderTime 33ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/moment/src/lib/moment/compare.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 59 lines | 53 code | 6 blank | 0 comment | 17 complexity | 82d031746e060a847112b5d7244e0d6d MD5 | raw file
 1import { isMoment } from './constructor';
 2import { normalizeUnits } from '../units/aliases';
 3import { createLocal } from '../create/local';
 4import isUndefined from '../utils/is-undefined';
 5
 6export function isAfter (input, units) {
 7    var localInput = isMoment(input) ? input : createLocal(input);
 8    if (!(this.isValid() && localInput.isValid())) {
 9        return false;
10    }
11    units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
12    if (units === 'millisecond') {
13        return this.valueOf() > localInput.valueOf();
14    } else {
15        return localInput.valueOf() < this.clone().startOf(units).valueOf();
16    }
17}
18
19export function isBefore (input, units) {
20    var localInput = isMoment(input) ? input : createLocal(input);
21    if (!(this.isValid() && localInput.isValid())) {
22        return false;
23    }
24    units = normalizeUnits(!isUndefined(units) ? units : 'millisecond');
25    if (units === 'millisecond') {
26        return this.valueOf() < localInput.valueOf();
27    } else {
28        return this.clone().endOf(units).valueOf() < localInput.valueOf();
29    }
30}
31
32export function isBetween (from, to, units, inclusivity) {
33    inclusivity = inclusivity || '()';
34    return (inclusivity[0] === '(' ? this.isAfter(from, units) : !this.isBefore(from, units)) &&
35        (inclusivity[1] === ')' ? this.isBefore(to, units) : !this.isAfter(to, units));
36}
37
38export function isSame (input, units) {
39    var localInput = isMoment(input) ? input : createLocal(input),
40        inputMs;
41    if (!(this.isValid() && localInput.isValid())) {
42        return false;
43    }
44    units = normalizeUnits(units || 'millisecond');
45    if (units === 'millisecond') {
46        return this.valueOf() === localInput.valueOf();
47    } else {
48        inputMs = localInput.valueOf();
49        return this.clone().startOf(units).valueOf() <= inputMs && inputMs <= this.clone().endOf(units).valueOf();
50    }
51}
52
53export function isSameOrAfter (input, units) {
54    return this.isSame(input, units) || this.isAfter(input,units);
55}
56
57export function isSameOrBefore (input, units) {
58    return this.isSame(input, units) || this.isBefore(input,units);
59}