Updating date helper to use UTC.
This commit is contained in:
parent
9fb5e97330
commit
3d01ac17e9
|
@ -2,6 +2,7 @@ const dayjs = require("dayjs")
|
||||||
dayjs.extend(require("dayjs/plugin/duration"))
|
dayjs.extend(require("dayjs/plugin/duration"))
|
||||||
dayjs.extend(require("dayjs/plugin/advancedFormat"))
|
dayjs.extend(require("dayjs/plugin/advancedFormat"))
|
||||||
dayjs.extend(require("dayjs/plugin/relativeTime"))
|
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:
|
* 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)
|
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) => {
|
module.exports.duration = (str, pattern, format) => {
|
||||||
|
|
|
@ -356,6 +356,15 @@ describe("Cover a few complex use cases", () => {
|
||||||
expect(validity).toBe(true)
|
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 () => {
|
it("test a very complex duration output", async () => {
|
||||||
const currentTime = new Date(1612432082000).toISOString(),
|
const currentTime = new Date(1612432082000).toISOString(),
|
||||||
eventTime = new Date(1612432071000).toISOString()
|
eventTime = new Date(1612432071000).toISOString()
|
||||||
|
|
Loading…
Reference in New Issue