Sha256: af3c769946eb9866dcf40345ab99db7e65b0a57af6dc54b817750c0c7bb9be13

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

import { normalizeUnits, normalizeObjectUnits } from '../units/aliases';
import { getPrioritizedUnits } from '../units/priorities';
import { hooks } from '../utils/hooks';
import isFunction from '../utils/is-function';


export function makeGetSet (unit, keepTime) {
    return function (value) {
        if (value != null) {
            set(this, unit, value);
            hooks.updateOffset(this, keepTime);
            return this;
        } else {
            return get(this, unit);
        }
    };
}

export function get (mom, unit) {
    return mom.isValid() ?
        mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]() : NaN;
}

export function set (mom, unit, value) {
    if (mom.isValid()) {
        mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);
    }
}

// MOMENTS

export function stringGet (units) {
    units = normalizeUnits(units);
    if (isFunction(this[units])) {
        return this[units]();
    }
    return this;
}


export function stringSet (units, value) {
    if (typeof units === 'object') {
        units = normalizeObjectUnits(units);
        var prioritized = getPrioritizedUnits(units);
        for (var i = 0; i < prioritized.length; i++) {
            this[prioritized[i].unit](units[prioritized[i].unit]);
        }
    } else {
        units = normalizeUnits(units);
        if (isFunction(this[units])) {
            return this[units](value);
        }
    }
    return this;
}

Version data entries

7 entries across 7 versions & 5 rubygems

Version Path
cortex-0.1.3 spec/dummy/node_modules/moment/src/lib/moment/get-set.js
jinda_lte-0.0.1 lib/generators/jinda_lte/templates/app/assets/jinda_assets/bower_components/moment/src/lib/moment/get-set.js
binnacle-0.5.0 vendor/assets/javascripts/moment/src/lib/moment/get-set.js
binnacle-0.4.9 vendor/assets/javascripts/moment/src/lib/moment/get-set.js
binnacle-0.4.8 vendor/assets/javascripts/moment/src/lib/moment/get-set.js
lanes-0.8.0 node_modules/moment/src/lib/moment/get-set.js
date_picker-0.0.9 test/dummy/vendor/assets/components/moment/src/lib/moment/get-set.js