From 94be3b61cbe60a002d40baa09130955ce98ecea7 Mon Sep 17 00:00:00 2001 From: Valya <68596159+valya@users.noreply.github.com> Date: Thu, 12 Jan 2023 15:06:34 +0000 Subject: [PATCH] fix: Test failing for toDate from string extension test (no-changelog) (#5142) --- .../test/ExpressionExtensions/DateExtensions.test.ts | 5 +++-- packages/workflow/test/ExpressionExtensions/Helpers.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/workflow/test/ExpressionExtensions/DateExtensions.test.ts b/packages/workflow/test/ExpressionExtensions/DateExtensions.test.ts index 5084fca09a..bd51a5cdff 100644 --- a/packages/workflow/test/ExpressionExtensions/DateExtensions.test.ts +++ b/packages/workflow/test/ExpressionExtensions/DateExtensions.test.ts @@ -4,7 +4,7 @@ import { extend } from '@/Extensions'; import { dateExtensions } from '@/Extensions/DateExtensions'; -import { evaluate } from './Helpers'; +import { evaluate, getLocalISOString } from './Helpers'; describe('Data Transformation Functions', () => { describe('Date Data Transformation Functions', () => { @@ -47,7 +47,8 @@ describe('Data Transformation Functions', () => { }); test('.toDate() should work on a string', () => { - expect(evaluate('={{ "2022-01-03T00:00:00.000+00:00".toDate() }}')).toEqual(new Date(2022, 0, 3)); + const date = new Date(2022, 0, 3); + expect(evaluate(`={{ "${getLocalISOString(date)}".toDate() }}`)).toEqual(date); }); }); }); diff --git a/packages/workflow/test/ExpressionExtensions/Helpers.ts b/packages/workflow/test/ExpressionExtensions/Helpers.ts index 9d5307bdec..1a36df85a6 100644 --- a/packages/workflow/test/ExpressionExtensions/Helpers.ts +++ b/packages/workflow/test/ExpressionExtensions/Helpers.ts @@ -31,3 +31,12 @@ export const evaluate = (value: string, values?: INodeExecutionData[]) => 'America/New_York', {}, ); + +export const getLocalISOString = (date: Date) => { + const offset = date.getTimezoneOffset(); + const offsetAbs = Math.abs(offset); + const isoString = new Date(date.getTime() - offset * 60 * 1000).toISOString(); + const hours = String(Math.floor(offsetAbs / 60)).padStart(2, '0'); + const minutes = String(offsetAbs % 60).padStart(2, '0'); + return `${isoString.slice(0, -1)}${offset > 0 ? '-' : '+'}${hours}:${minutes}`; +};