Skip to content

Commit

Permalink
Specify ISO format for consistent browser parsing (#2972)
Browse files Browse the repository at this point in the history
Co-authored-by: Stuart Runyan <shrunyan@gmail.com>
  • Loading branch information
agalin920 and shrunyan authored Oct 22, 2024
1 parent 6ed1c96 commit 3a495b7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/shell/components/FieldTypeDateTime/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,12 +1469,17 @@ export const TIMEZONES = [
},
] as const;

// Specify exact ISO format. This ensures consistent parsing across different browsers.
const ISO_FORMAT = "MM/DD/YYYY HH:mm:ss.SSSSSS";

export const toISOString = (timeString: string) => {
return moment(`01-01-2024 ${timeString}`).format("HH:mm:ss.SSSSSS");
return moment(`01-01-2024 ${timeString}`, ISO_FORMAT).format(
"HH:mm:ss.SSSSSS"
);
};

export const to12HrTime = (isoTime: string) => {
return moment(`01/01/2024 ${isoTime}`).format("h:mm a");
return moment(`01/01/2024 ${isoTime}`, ISO_FORMAT).format("h:mm a");
};

const generateTimeOptions = () => {
Expand Down

0 comments on commit 3a495b7

Please sign in to comment.