Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #722 from MeasureAuthoringTool/MAT-7679_DateTimeCo…
Browse files Browse the repository at this point in the history
…mponent

MAT-7679 add other supported time zones
  • Loading branch information
sb-cecilialiu authored Oct 9, 2024
2 parents 9278615 + 48c2f65 commit 3d07c90
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@ interface MenuObj {
label: string;
}
const options: MenuObj[] = [
{ value: "America/Puerto_Rico", label: "AST" },
{ value: "America/New_York", label: "EST" },
{ value: "America/Chicago", label: "CST" },
{ value: "America/Denver", label: "MST" },
{ value: "America/Los_Angeles", label: "PST" },
{ value: "America/Anchorage", label: "AKST" },
{ value: "America/honolulu", label: "HST" },
{ value: "America/American_Samoa", label: "WST" },
{ value: "America/Saipan", label: "CHST" },
];

const offSets = [
{ id: "America/Puerto_Rico - AST", value: "-04:00" },
{ id: "America/New_York - EST", value: "-05:00" },
{ id: "America/Chicago - CST", value: "-06:00" },
{ id: "America/Denver - MST", value: "-07:00" },
{ id: "America/Los_Angeles - PST", value: "-08:00" },
{ id: "America/Anchorage - AKST", value: "-09:00" },
{ id: "America/honolulu - HST", value: "-10:00" },
{ id: "America/American_Samoa - WST", value: "-11:00" },
{ id: "America/Saipan - CHST", value: "+10:00" },
];

const findByLabel = (value) => {
Expand Down Expand Up @@ -65,6 +75,18 @@ const getOffSet = (value) => {
return result;
};

const findByOffSet = (value) => {
let result = "America/New_York - EST";
if (value) {
offSets.forEach((opt) => {
if (opt.value === value) {
result = opt.id;
}
});
}
return result;
};

const DateTimeComponent = ({
canEdit,
fieldRequired,
Expand Down Expand Up @@ -99,6 +121,9 @@ const DateTimeComponent = ({
converted = convertToStandardTime(converted).tz(userTimeZone);

setTimeZone(findByLabel(timezoneName.replace("D", "S")));
} else if (timezoneName.includes("GMT")) {
const zone = findByOffSet(timezoneName.substring(3, 6) + ":00");
setTimeZone(zone);
} else {
setTimeZone(findByLabel(timezoneName));
}
Expand Down

0 comments on commit 3d07c90

Please sign in to comment.