dd26c3cd96f6f611484a9c970a3b4e07f40141142d22cf3716bceb6f2811c3a62a6ec4bf2edf8a1fec9184bdc25aa5834b3f989aec778e0a7bd12faea95898 1.4 KB

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