add-subtract.js (644B)
1import { createDuration } from './create'; 2 3function addSubtract(duration, input, value, direction) { 4 var other = createDuration(input, value); 5 6 duration._milliseconds += direction * other._milliseconds; 7 duration._days += direction * other._days; 8 duration._months += direction * other._months; 9 10 return duration._bubble(); 11} 12 13// supports only 2.0-style add(1, 's') or add(duration) 14export function add(input, value) { 15 return addSubtract(this, input, value, 1); 16} 17 18// supports only 2.0-style subtract(1, 's') or subtract(duration) 19export function subtract(input, value) { 20 return addSubtract(this, input, value, -1); 21}