Skip to content

Commit

Permalink
HPCC-29403 Allow disabling time zone adjustments in ECLWatch
Browse files Browse the repository at this point in the history
Toggle Button added to switch between Local and UTC timezones.

Signed-off-by: Kunal Aswani <[email protected]>
  • Loading branch information
kunalaswani committed Jul 24, 2024
1 parent 5f1f8ae commit b625998
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
33 changes: 30 additions & 3 deletions esp/src/src-react/components/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function formatQuery(_filter): { [id: string]: any } {

const defaultUIState = {
hasSelection: false,
isUTC: false,
};

interface FilesProps {
Expand Down Expand Up @@ -127,6 +128,25 @@ export const Files: React.FunctionComponent<FilesProps> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasFocus]);

const toggleTimezone = () => {
setUIState((prevState) => ({ ...prevState, isUTC: !prevState.isUTC }));
};

React.useEffect(() => {
localStorage.setItem("isUTC", JSON.stringify(uiState.isUTC));
}, [uiState.isUTC]);

React.useEffect(() => {
const storedIsUTC = JSON.parse(localStorage.getItem("isUTC"));
if (storedIsUTC !== null) {
setUIState((prevState) => ({ ...prevState, isUTC: storedIsUTC }));
}
}, []);

const currentTime = React.useCallback(timestamp => {
const date = new Date(timestamp);
return date.toUTCString();
}, []);
// Grid ---
const gridStore = React.useMemo(() => {
return store ? store : CreateDFUQueryStore();
Expand Down Expand Up @@ -216,8 +236,8 @@ export const Files: React.FunctionComponent<FilesProps> = ({
MaxSkew: {
label: nlsHPCC.MaxSkew, width: 60, formatter: (value, row) => value ? `${Utility.formatDecimal(value / 100)}%` : ""
},
Modified: { label: nlsHPCC.ModifiedUTCGMT },
Accessed: { label: nlsHPCC.LastAccessed },
Modified: { label: nlsHPCC.ModifiedUTCGMT, formatter: currentTime },
AtRestCost: {
label: nlsHPCC.FileCostAtRest,
formatter: (cost, row) => {
Expand Down Expand Up @@ -321,7 +341,14 @@ export const Files: React.FunctionComponent<FilesProps> = ({
pushParams(filter);
}
},
], [currentUser, filter, hasFilter, refreshTable, selection, setShowDeleteConfirm, store, total, uiState.hasSelection, viewByScope]);
{ key: "divider_6", itemType: ContextualMenuItemType.Divider, onRender: () => <ShortVerticalDivider /> },
{
key: "toggleTimezone",
text: uiState.isUTC ? nlsHPCC.SwitchToLocalTime : nlsHPCC.SwitchToUTCTime,
iconProps: { iconName: uiState.isUTC ? "Globe" : "Clock" },
onClick: toggleTimezone,
},
], [currentUser, filter, hasFilter, refreshTable, selection, setShowDeleteConfirm, store, total, uiState.hasSelection, viewByScope, uiState.isUTC]);

// Filter ---
const filterFields: Fields = {};
Expand Down Expand Up @@ -382,4 +409,4 @@ export const Files: React.FunctionComponent<FilesProps> = ({
></FluentPagedFooter>}
footerStyles={{}}
/>;
};
};
11 changes: 10 additions & 1 deletion esp/src/src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,4 +1307,13 @@ export function wuidToTime(wuid: string): string {

export function wuidToDateTime(wuid: string): Date {
return new Date(`${wuidToDate(wuid)}T${wuidToTime(wuid)}Z`);
}
}
export function convertToLocalTime(dateString) {
const modifiedDate = new Date(dateString);
return modifiedDate.toLocaleString();
}

export function convertToUTCTime(dateString) {
const modifiedDate = new Date(dateString);
return modifiedDate.toUTCString();
}
2 changes: 2 additions & 0 deletions esp/src/src/nls/hpcc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@ export = {
SuspendedReason: "Suspended Reason",
Statistics: "Statistics",
SVGSource: "SVG Source",
SwitchToLocalTime:"Switch to Local Time",
SwitchToUTCTime:"Switch to UTC Time",
SyncSelection: "Sync To Selection",
Syntax: "Syntax",
SystemServers: "System Servers",
Expand Down

0 comments on commit b625998

Please sign in to comment.