Skip to content

Commit

Permalink
fix: align timezone with actual delivery times (#265)
Browse files Browse the repository at this point in the history
INT-452

---------

Co-authored-by: Clerise Swart <[email protected]>
  • Loading branch information
MPClerise and Clerise Swart authored Dec 31, 2024
1 parent 1bde91f commit 4b92024
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions apps/delivery-options/src/utils/stringToDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 4b92024

Please sign in to comment.