diff --git a/packages/string-templates/src/helpers/date.js b/packages/string-templates/src/helpers/date.js index 0d9bd78036..ce845eee3f 100644 --- a/packages/string-templates/src/helpers/date.js +++ b/packages/string-templates/src/helpers/date.js @@ -2,6 +2,7 @@ const dayjs = require("dayjs") dayjs.extend(require("dayjs/plugin/duration")) dayjs.extend(require("dayjs/plugin/advancedFormat")) dayjs.extend(require("dayjs/plugin/relativeTime")) +dayjs.extend(require("dayjs/plugin/utc")) /** * This file was largely taken from the helper-date package - we did this for two reasons: @@ -88,7 +89,11 @@ module.exports.date = (str, pattern, options) => { setLocale(config.str, config.pattern, config.options) - return dayjs(new Date(config.str)).format(config.pattern) + const date = dayjs(new Date(config.str)).utc() + if (config.pattern === "") { + return date.toISOString() + } + return date.format(config.pattern) } module.exports.duration = (str, pattern, format) => { diff --git a/packages/string-templates/test/helpers.spec.js b/packages/string-templates/test/helpers.spec.js index 0217395537..6be8e2ed0e 100644 --- a/packages/string-templates/test/helpers.spec.js +++ b/packages/string-templates/test/helpers.spec.js @@ -356,6 +356,15 @@ describe("Cover a few complex use cases", () => { expect(validity).toBe(true) }) + it("should test a case of attempting to get a UTC ISO back out after processing", async () => { + const date = new Date() + const input = `{{ date (subtract (date dateThing "x") 300000) "" }}` + const output = await processString(input, { + dateThing: date.toISOString(), + }) + expect(output).toEqual(new Date(date.getTime() - 300000).toISOString()) + }) + it("test a very complex duration output", async () => { const currentTime = new Date(1612432082000).toISOString(), eventTime = new Date(1612432071000).toISOString()