3ce3addeacc8065d017aa1f47228b594d06b530d8335ddd637e27a52b9ed92079916123d9835146d7b128cd58c415e16f4795d3c6f946c7bd59d8977c7e25c 2.1 KB

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