From 4b920245bef0341fe1d45a3544619aba5cb22b6c Mon Sep 17 00:00:00 2001 From: Clerise Date: Tue, 31 Dec 2024 10:27:05 +0200 Subject: [PATCH] fix: align timezone with actual delivery times (#265) INT-452 --------- Co-authored-by: Clerise Swart --- apps/delivery-options/src/utils/stringToDate.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/delivery-options/src/utils/stringToDate.ts b/apps/delivery-options/src/utils/stringToDate.ts index a0eb54de..4e18d799 100644 --- a/apps/delivery-options/src/utils/stringToDate.ts +++ b/apps/delivery-options/src/utils/stringToDate.ts @@ -31,13 +31,17 @@ export const stringToDate = (date: string): Date => { const timeWithoutDate = date.substring(DATE_LENGTH + 1, date.length); /** - * Split the date and time, passing the year, month, day, hours, minutes and seconds as arguments to Date.UTC to - * create a UTC date. + * Split the time into individual components and convert them to numbers. * - * @example 2019 10 15 17 00 00.000000 -> 1573837200000 + * @example 08:00:00 -> [8, 0, 0] */ - // @ts-expect-error todo - const utcDate = Date.UTC(...dateArr, ...timeWithoutDate.split(':')); + const [hours, minutes, seconds] = timeWithoutDate.split(':').map(Number); - return new Date(utcDate); + /** + * Create a Date object using the parsed year, adjusted month, day, hours, minutes, and seconds. + * This avoids any timezone adjustments, treating the input as a plain date and time. + * + * @example new Date(2019, 9, 15, 8, 0, 0) + */ + return new Date(parseInt(dateArr[0]), parseInt(dateArr[1]), parseInt(dateArr[2]), hours, minutes, seconds); };