Skip to content

Commit

Permalink
fix: use timezone offset when grouping operations in OperationTree
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Dec 21, 2023
1 parent 48d80b9 commit 06240bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 4 additions & 5 deletions webui/src/components/OperationTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
formatDate,
formatDuration,
formatTime,
localISOTime,
normalizeSnapshotId,
} from "../lib/formatting";
import {
Expand All @@ -40,7 +41,6 @@ export const OperationTree = ({

// track backups for this operation tree view.
useEffect(() => {
console.log("using effect");
setSelectedBackupId(null);
const backupCollector = new BackupInfoCollector();
const lis = (opEvent: OperationEvent) => {
Expand Down Expand Up @@ -125,7 +125,6 @@ export const OperationTree = ({
setSelectedBackupId(null);
return;
}
console.log("SELECTED ID: " + backup.id);
setSelectedBackupId(backup.id!);
}}
titleRender={(node: OpTreeNode): React.ReactNode => {
Expand Down Expand Up @@ -205,7 +204,7 @@ export const OperationTree = ({

const buildTreeYear = (operations: BackupInfo[]): OpTreeNode[] => {
const grouped = _.groupBy(operations, (op) => {
return op.displayTime.toISOString().substring(0, 4);
return localISOTime(op.displayTime).substring(0, 4);
});

const entries: OpTreeNode[] = _.map(grouped, (value, key) => {
Expand All @@ -221,7 +220,7 @@ const buildTreeYear = (operations: BackupInfo[]): OpTreeNode[] => {

const buildTreeMonth = (operations: BackupInfo[]): OpTreeNode[] => {
const grouped = _.groupBy(operations, (op) => {
return op.displayTime.toISOString().substring(0, 7);
return localISOTime(op.displayTime).substring(0, 7);
});
const entries: OpTreeNode[] = _.map(grouped, (value, key) => {
return {
Expand All @@ -238,7 +237,7 @@ const buildTreeMonth = (operations: BackupInfo[]): OpTreeNode[] => {

const buildTreeDay = (operations: BackupInfo[]): OpTreeNode[] => {
const grouped = _.groupBy(operations, (op) => {
return op.displayTime.toISOString().substring(0, 10);
return localISOTime(op.displayTime).substring(0, 10);
});

const entries = _.map(grouped, (value, key) => {
Expand Down
12 changes: 12 additions & 0 deletions webui/src/lib/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export const formatTime = (time: number | string | Date) => {
}`;
};

export const localISOTime = (time: number | string | Date) => {
if (typeof time === "string") {
time = parseInt(time);
} else if (time instanceof Date) {
time = time.getTime();
}

const d = new Date();
d.setTime(time - timezoneOffsetMs);
return d.toISOString();
}

// formatDate formats a time as YYYY-MM-DD
export const formatDate = (time: number | string | Date) => {
if (typeof time === "string") {
Expand Down

0 comments on commit 06240bd

Please sign in to comment.