From f475b05c51ce02bec18dd873f3408904e33fcb09 Mon Sep 17 00:00:00 2001 From: Zhizhen He Date: Wed, 29 Oct 2025 23:15:19 +0800 Subject: [PATCH] Allow specifying time for unix / unix millis / iso 8601 format (#283) Co-authored-by: Gregory Schier --- .../template-function-timestamp/src/index.ts | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/plugins/template-function-timestamp/src/index.ts b/plugins/template-function-timestamp/src/index.ts index 1f1b156a..b5f30b4b 100755 --- a/plugins/template-function-timestamp/src/index.ts +++ b/plugins/template-function-timestamp/src/index.ts @@ -52,21 +52,30 @@ export const plugin: PluginDefinition = { templateFunctions: [ { name: 'timestamp.unix', - description: 'Get the current timestamp in seconds', - args: [], - onRender: async () => String(Math.floor(Date.now() / 1000)), + description: 'Get the timestamp in seconds', + args: [dateArg], + onRender: async (_ctx, args) => { + const d = parseDateString(String(args.values.date ?? '')); + return String(Math.floor(d.getTime() / 1000)); + }, }, { name: 'timestamp.unixMillis', - description: 'Get the current timestamp in milliseconds', - args: [], - onRender: async () => String(Date.now()), + description: 'Get the timestamp in milliseconds', + args: [dateArg], + onRender: async (_ctx, args) => { + const d = parseDateString(String(args.values.date ?? '')); + return String(d.getTime()); + }, }, { name: 'timestamp.iso8601', - description: 'Get the current date in ISO8601 format', - args: [], - onRender: async () => new Date().toISOString(), + description: 'Get the date in ISO8601 format', + args: [dateArg], + onRender: async (_ctx, args) => { + const d = parseDateString(String(args.values.date ?? '')); + return d.toISOString(); + }, }, { name: 'timestamp.format',