diff --git a/util.ts b/util.ts index e593432..a2bf711 100644 --- a/util.ts +++ b/util.ts @@ -22,7 +22,7 @@ function isNonPrimitive(value: any): value is object { /** Recursively copy a value. -@param source - should be a JavaScript primitive, Array, or (plain old) Object. +@param source - should be a JavaScript primitive, Array, Date, or (plain old) Object. @returns copy of source where every Array and Object have been recursively reconstructed from their constituent elements */ @@ -42,6 +42,11 @@ export function clone(source: T): T { } return arrayTarget } + // Date + if (source.constructor == Date) { + const dateTarget: any = new Date(+source) + return dateTarget + } // Object const objectTarget: any = {} // declaring the variable (with const) inside the loop is faster