aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/duration/constructor.js
diff options
context:
space:
mode:
Diffstat (limited to 'library/moment/src/lib/duration/constructor.js')
-rw-r--r--library/moment/src/lib/duration/constructor.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/library/moment/src/lib/duration/constructor.js b/library/moment/src/lib/duration/constructor.js
new file mode 100644
index 000000000..884c6f8c8
--- /dev/null
+++ b/library/moment/src/lib/duration/constructor.js
@@ -0,0 +1,41 @@
+import { normalizeObjectUnits } from '../units/aliases';
+import { getLocale } from '../locale/locales';
+
+export function Duration (duration) {
+ var normalizedInput = normalizeObjectUnits(duration),
+ years = normalizedInput.year || 0,
+ quarters = normalizedInput.quarter || 0,
+ months = normalizedInput.month || 0,
+ weeks = normalizedInput.week || 0,
+ days = normalizedInput.day || 0,
+ hours = normalizedInput.hour || 0,
+ minutes = normalizedInput.minute || 0,
+ seconds = normalizedInput.second || 0,
+ milliseconds = normalizedInput.millisecond || 0;
+
+ // representation for dateAddRemove
+ this._milliseconds = +milliseconds +
+ seconds * 1e3 + // 1000
+ minutes * 6e4 + // 1000 * 60
+ hours * 36e5; // 1000 * 60 * 60
+ // Because of dateAddRemove treats 24 hours as different from a
+ // 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
+ // which months you are are talking about, so we have to store
+ // it separately.
+ this._months = +months +
+ quarters * 3 +
+ years * 12;
+
+ this._data = {};
+
+ this._locale = getLocale();
+
+ this._bubble();
+}
+
+export function isDuration (obj) {
+ return obj instanceof Duration;
+}