cbc4ed82dea9c4204176194e93a91bab79e5333c9c345e42592f0b920cfea5f58aa613d30ba2f7205ba8ab71b99f5e023e679fc3eaf627494426b7427f06af 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { hooks } from '../utils/hooks';
  2. import hasOwnProp from '../utils/has-own-prop';
  3. import isUndefined from '../utils/is-undefined';
  4. import getParsingFlags from '../create/parsing-flags';
  5. // Plugins that add properties should also add the key here (null value),
  6. // so we can properly clone ourselves.
  7. var momentProperties = hooks.momentProperties = [];
  8. export function copyConfig(to, from) {
  9. var i, prop, val;
  10. if (!isUndefined(from._isAMomentObject)) {
  11. to._isAMomentObject = from._isAMomentObject;
  12. }
  13. if (!isUndefined(from._i)) {
  14. to._i = from._i;
  15. }
  16. if (!isUndefined(from._f)) {
  17. to._f = from._f;
  18. }
  19. if (!isUndefined(from._l)) {
  20. to._l = from._l;
  21. }
  22. if (!isUndefined(from._strict)) {
  23. to._strict = from._strict;
  24. }
  25. if (!isUndefined(from._tzm)) {
  26. to._tzm = from._tzm;
  27. }
  28. if (!isUndefined(from._isUTC)) {
  29. to._isUTC = from._isUTC;
  30. }
  31. if (!isUndefined(from._offset)) {
  32. to._offset = from._offset;
  33. }
  34. if (!isUndefined(from._pf)) {
  35. to._pf = getParsingFlags(from);
  36. }
  37. if (!isUndefined(from._locale)) {
  38. to._locale = from._locale;
  39. }
  40. if (momentProperties.length > 0) {
  41. for (i in momentProperties) {
  42. prop = momentProperties[i];
  43. val = from[prop];
  44. if (!isUndefined(val)) {
  45. to[prop] = val;
  46. }
  47. }
  48. }
  49. return to;
  50. }
  51. var updateInProgress = false;
  52. // Moment prototype object
  53. export function Moment(config) {
  54. copyConfig(this, config);
  55. this._d = new Date(config._d != null ? config._d.getTime() : NaN);
  56. // Prevent infinite loop in case updateOffset creates new moment
  57. // objects.
  58. if (updateInProgress === false) {
  59. updateInProgress = true;
  60. hooks.updateOffset(this);
  61. updateInProgress = false;
  62. }
  63. }
  64. export function isMoment (obj) {
  65. return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);
  66. }