Skip to content

Commit

Permalink
fix: parse dates passed from $json in extend function
Browse files Browse the repository at this point in the history
  • Loading branch information
valya committed Oct 24, 2022
1 parent 5e55209 commit d99e7e9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/workflow/src/Extensions/ExpressionExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const extendTransform = (expression: string): { code: string } | undefine
}
};

function isDate(input: unknown): boolean {
if (typeof input !== 'string') {
return false;
}
return !isNaN(new Date(input).valueOf());
}

/**
* Extender function injected by expression extension plugin to allow calls to extensions.
*
Expand All @@ -147,12 +154,16 @@ export function extend(input: unknown, functionName: string, args: unknown[]) {
let foundFunction: Function | undefined;
if (Array.isArray(input)) {
foundFunction = arrayExtensions.functions[functionName];
} else if (isDate(input)) {
// If it's a string date (from $json), convert it to a Date object
input = new Date(input as string);
foundFunction = dateExtensions.functions[functionName];
} else if ('isLuxonDateTime' in (input as DateTime) || input instanceof Date) {
foundFunction = dateExtensions.functions[functionName];
} else if (typeof input === 'string') {
foundFunction = stringExtensions.functions[functionName];
} else if (typeof input === 'number') {
foundFunction = numberExtensions.functions[functionName];
} else if ('isLuxonDateTime' in (input as DateTime) || input instanceof Date) {
foundFunction = dateExtensions.functions[functionName];
}

// Look for generic or builtin
Expand Down

0 comments on commit d99e7e9

Please sign in to comment.