Sha256: 4433c3dc350ec86f23c3c4412805a01bf8d7d8c6ca20eb6125f075b6eb480128

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

import { get, set } from './get-set';
import { setMonth } from '../units/month';
import { createDuration } from '../duration/create';
import { deprecateSimple } from '../utils/deprecate';
import { hooks } from '../utils/hooks';
import absRound from '../utils/abs-round';


// TODO: remove 'name' arg after deprecation is removed
function createAdder(direction, name) {
    return function (val, period) {
        var dur, tmp;
        //invert the arguments, but complain about it
        if (period !== null && !isNaN(+period)) {
            deprecateSimple(name, 'moment().' + name  + '(period, number) is deprecated. Please use moment().' + name + '(number, period). ' +
            'See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.');
            tmp = val; val = period; period = tmp;
        }

        val = typeof val === 'string' ? +val : val;
        dur = createDuration(val, period);
        addSubtract(this, dur, direction);
        return this;
    };
}

export function addSubtract (mom, duration, isAdding, updateOffset) {
    var milliseconds = duration._milliseconds,
        days = absRound(duration._days),
        months = absRound(duration._months);

    if (!mom.isValid()) {
        // No op
        return;
    }

    updateOffset = updateOffset == null ? true : updateOffset;

    if (milliseconds) {
        mom._d.setTime(mom._d.valueOf() + milliseconds * isAdding);
    }
    if (days) {
        set(mom, 'Date', get(mom, 'Date') + days * isAdding);
    }
    if (months) {
        setMonth(mom, get(mom, 'Month') + months * isAdding);
    }
    if (updateOffset) {
        hooks.updateOffset(mom, days || months);
    }
}

export var add      = createAdder(1, 'add');
export var subtract = createAdder(-1, 'subtract');

Version data entries

7 entries across 7 versions & 5 rubygems

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