import { getLocale } from '../locale/locales';
import { bubble } from './bubble';
import isDurationValid from './valid';
+import extend from '../utils/extend';
export function Duration (duration) {
var normalizedInput = normalizeObjectUnits(duration),
seconds = normalizedInput.second || 0,
milliseconds = normalizedInput.millisecond || 0;
+ if (isDuration(duration)) {
+ copyDuration(this, duration);
+ return;
+ }
+
this._isValid = isDurationValid(normalizedInput);
// representation for dateAddRemove
// day when working around DST, we need to store them separately
this._days = +days +
weeks * 7;
- // It is impossible translate months into days without knowing
+ // It is impossible to translate months into days without knowing
// which months you are are talking about, so we have to store
// it separately.
this._months = +months +
export function isDuration (obj) {
return obj instanceof Duration;
}
+
+function copyDuration(to, from) {
+ to._isValid = from._isValid;
+ to._milliseconds = from._milliseconds;
+ to._days = from._days;
+ to._months = from._months;
+ to._data = extend({}, from._data);
+ to._locale = from._locale;
+}