1 import { normalizeObjectUnits } from '../units/aliases';
2 import { getLocale } from '../locale/locales';
4 export function Duration (duration) {
5 var normalizedInput = normalizeObjectUnits(duration),
6 years = normalizedInput.year || 0,
7 quarters = normalizedInput.quarter || 0,
8 months = normalizedInput.month || 0,
9 weeks = normalizedInput.week || 0,
10 days = normalizedInput.day || 0,
11 hours = normalizedInput.hour || 0,
12 minutes = normalizedInput.minute || 0,
13 seconds = normalizedInput.second || 0,
14 milliseconds = normalizedInput.millisecond || 0;
16 // representation for dateAddRemove
17 this._milliseconds = +milliseconds +
18 seconds * 1e3 + // 1000
19 minutes * 6e4 + // 1000 * 60
20 hours * 1000 * 60 * 60; //using 1000 * 60 * 60 instead of 36e5 to avoid floating point rounding errors https://github.com/moment/moment/issues/2978
21 // Because of dateAddRemove treats 24 hours as different from a
22 // day when working around DST, we need to store them separately
25 // It is impossible translate months into days without knowing
26 // which months you are are talking about, so we have to store
28 this._months = +months +
34 this._locale = getLocale();
39 export function isDuration (obj) {
40 return obj instanceof Duration;