Sha256: 7ba1a0878967a2566d7ac1b2be1921b89632cbefd9bf3ddc81900e71dba04aa6

Contents?: true

Size: 1.51 KB

Versions: 19

Compression:

Stored size: 1.51 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';

// 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).');
            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 = duration._days,
        months = duration._months;
    updateOffset = updateOffset == null ? true : updateOffset;

    if (milliseconds) {
        mom._d.setTime(+mom._d + 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

19 entries across 19 versions & 4 rubygems

Version Path
active_record_survey_api-0.0.19 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.18 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.17 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.14 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.12 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.11 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.7 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
active_record_survey_api-0.0.6 spec/test_app/vendor/assets/bower_components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.8 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.7 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
sedge_cms-0.0.1 vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.6 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.5 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.4 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.3 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.2 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
date_picker-0.0.1 test/dummy/vendor/assets/components/moment/src/lib/moment/add-subtract.js
puppet-herald-0.8.1 lib/puppet-herald/public/bower_components/moment/src/lib/moment/add-subtract.js
puppet-herald-0.8.0 lib/puppet-herald/public/bower_components/moment/src/lib/moment/add-subtract.js