From ebb1fb8089fb3a4034292a9c5f56be989d1a76b6 Mon Sep 17 00:00:00 2001 From: David Graham Date: Mon, 3 Oct 2022 09:25:19 -0600 Subject: [PATCH] Remove timezone from sanitized date strings Including the `Z` timezone works in select statements but throws an "incorrect datetime value" error during insert. Strip the timezone from the string before using it as a parameter replacement value. --- __tests__/sanitization.test.ts | 2 +- src/sanitization.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/sanitization.test.ts b/__tests__/sanitization.test.ts index e876a08..0c06a73 100644 --- a/__tests__/sanitization.test.ts +++ b/__tests__/sanitization.test.ts @@ -57,7 +57,7 @@ describe('sanitization', () => { test('formats date values', () => { const ts = Date.UTC(2022, 1, 8, 13, 15, 45) const query = 'select 1 from user where created_at > ?' - const expected = "select 1 from user where created_at > '2022-02-08T13:15:45.000Z'" + const expected = "select 1 from user where created_at > '2022-02-08T13:15:45.000'" expect(format(query, [new Date(ts)])).toEqual(expected) }) diff --git a/src/sanitization.ts b/src/sanitization.ts index 9736d21..efb5f26 100644 --- a/src/sanitization.ts +++ b/src/sanitization.ts @@ -44,7 +44,7 @@ function sanitize(value: Value): string { } if (value instanceof Date) { - return quote(value.toISOString()) + return quote(value.toISOString().replace('Z', '')) } return quote(value.toString())