Skip to content

Commit 4811c15

Browse files
feat(date): Default show datetime in local timezone instead of UTC
Resolves: flyteorg/flyte#2908 Signed-off-by: Chi-Sheng Liu <[email protected]>
1 parent eb7fe2b commit 4811c15

File tree

6 files changed

+35
-36
lines changed

6 files changed

+35
-36
lines changed

packages/oss-console/src/common/formatters.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ import { durationToMilliseconds, isValidDate } from './utils';
88

99
const defaultUTCFormat = 'l LTS';
1010

11-
/** Formats a date into a standard string with a moment-style "from now" hint
12-
* ex. 12/21/2017 8:19:36 PM (18 days ago)
13-
*/
14-
export function dateWithFromNow(input: Date) {
15-
if (!isValidDate(input)) {
16-
return unknownValueString;
17-
}
18-
19-
const date = moment.utc(input);
20-
return `${date.format(defaultUTCFormat)} UTC (${date.fromNow()})`;
21-
}
22-
2311
/** Formats a date into a moment-style "from now" value */
2412
export function dateFromNow(input: Date) {
2513
if (!isValidDate(input)) {
@@ -51,7 +39,7 @@ export function formatDateUTC(input: Date, formatString?: string) {
5139
/**
5240
* Gets human-readable date relative to "now"
5341
*/
54-
export function formateDateRelative(input: Date, threshold = 24 * 60 * 60 * 1000) {
42+
export function formatDateRelative(input: Date, threshold = 24 * 60 * 60 * 1000) {
5543
if (!isValidDate(input)) {
5644
return unknownValueString;
5745
}
@@ -72,6 +60,18 @@ export function formatDateLocalTimezone(input: Date) {
7260
return isValidDate(input) ? moment(input).tz(timezone).format('l LTS z') : unknownValueString;
7361
}
7462

63+
/** Formats a date into a standard string with a moment-style "from now" hint
64+
* ex. 12/21/2017 8:19:36 PM (18 days ago)
65+
*/
66+
export function dateWithFromNow(input: Date) {
67+
if (!isValidDate(input)) {
68+
return unknownValueString;
69+
}
70+
71+
const date = moment.utc(input);
72+
return `${formatDateLocalTimezone(input)} (${date.fromNow()})`;
73+
}
74+
7575
/** Outputs a value in milliseconds in (H M S) format (ex. 2h 3m 30s) */
7676
export function millisecondsToHMS(valueMS: number): string {
7777
if (valueMS < 0) {

packages/oss-console/src/components/Executions/ExecutionDetails/ExecutionMetadata.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Link as RouterLink } from 'react-router-dom';
66
import styled from '@mui/system/styled';
77
import * as CommonStylesConstants from '@clients/theme/CommonStyles/constants';
88
import { dashedValueString } from '@clients/common/constants';
9-
import { formatDateUTC, protobufDurationToHMS } from '../../../common/formatters';
9+
import { formatDateLocalTimezone, protobufDurationToHMS } from '../../../common/formatters';
1010
import { timestampToDate } from '../../../common/utils';
1111
import { useCommonStyles } from '../../common/styles';
1212
import { Routes } from '../../../routes/routes';
@@ -85,7 +85,7 @@ export const ExecutionMetadata: React.FC<{}> = () => {
8585
},
8686
{
8787
label: ExecutionMetadataLabels.time,
88-
value: startedAt ? formatDateUTC(timestampToDate(startedAt)) : dashedValueString,
88+
value: startedAt ? formatDateLocalTimezone(timestampToDate(startedAt)) : dashedValueString,
8989
},
9090
{
9191
label: ExecutionMetadataLabels.duration,

packages/oss-console/src/components/Executions/ExecutionDetails/utils.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ResourceType } from '../../../models/Common/types';
22
import { Execution, NodeExecution, TaskExecution } from '../../../models/Execution/types';
33
import { timestampToDate } from '../../../common/utils';
4-
import { formatDateUTC } from '../../../common/formatters';
4+
import { formatDateLocalTimezone } from '../../../common/formatters';
55

66
export function isSingleTaskExecution(execution: Execution) {
77
return execution.spec.launchPlan.resourceType === ResourceType.TASK;
@@ -21,8 +21,9 @@ export function getTaskExecutionDetailReasons(
2121
reasons = reasons.concat(
2222
finalReasons.map(
2323
(reason) =>
24-
(reason.occurredAt ? `${formatDateUTC(timestampToDate(reason.occurredAt))} ` : '') +
25-
reason.message,
24+
(reason.occurredAt
25+
? `${formatDateLocalTimezone(timestampToDate(reason.occurredAt))} `
26+
: '') + reason.message,
2627
),
2728
);
2829
}

packages/oss-console/src/components/Executions/Tables/NodeExecutionsTable.tsx

+10-12
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,16 @@ export const NodeExecutionsTable: React.FC<{
254254
</TableHead>
255255
<TableBody>
256256
{showNodes.length > 0 ? (
257-
showNodes.map((node) => {
258-
return (
259-
<NodeExecutionDynamicProvider node={node} key={node.scopedId}>
260-
<NodeExecutionRow
261-
columns={columns}
262-
node={node}
263-
onToggle={toggleNode}
264-
key={node.scopedId}
265-
/>
266-
</NodeExecutionDynamicProvider>
267-
);
268-
})
257+
showNodes.map((node) => (
258+
<NodeExecutionDynamicProvider node={node} key={node.scopedId}>
259+
<NodeExecutionRow
260+
columns={columns}
261+
node={node}
262+
onToggle={toggleNode}
263+
key={node.scopedId}
264+
/>
265+
</NodeExecutionDynamicProvider>
266+
))
269267
) : (
270268
<TableNoRowsCell displayMessage={noExecutionsFoundString} />
271269
)}

packages/oss-console/src/components/Executions/Tables/WorkflowExecutionTable/cells.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import styled from '@mui/system/styled';
1616
import {
1717
formatDateLocalTimezone,
1818
formatDateUTC,
19-
formateDateRelative,
19+
formatDateRelative,
2020
millisecondsToHMS,
2121
} from '../../../../common/formatters';
2222
import { timestampToDate } from '../../../../common/utils';
@@ -83,7 +83,7 @@ export function getStartTimeCell(
8383
// const isArchived = isExecutionArchived(execution);
8484

8585
if (isRelativeStartTime) {
86-
return formateDateRelative(startedAtDate);
86+
return formatDateRelative(startedAtDate);
8787
}
8888

8989
const localTime = React.useMemo(() => {
@@ -113,8 +113,8 @@ export function getStartTimeCell(
113113
}
114114
return `${h}h ${m}m ago`;
115115
}
116-
return utc;
117-
}, [startedAtDate, utc]);
116+
return localTime;
117+
}, [startedAtDate, localTime]);
118118

119119
const tooltipText = React.useMemo(() => {
120120
const isLast24Hours = moment().diff(startedAtDate, 'hours') < 24;

packages/oss-console/src/components/Executions/Tables/nodeExecutionColumns.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ export function generateColumns(
123123
return (
124124
<>
125125
<Typography variant="body1" className={className}>
126-
{formatDateUTC(startedAtDate)}
126+
{formatDateLocalTimezone(startedAtDate)}
127127
</Typography>
128128
<Typography variant="subtitle1" color="textSecondary" className={className}>
129-
{formatDateLocalTimezone(startedAtDate)}
129+
{formatDateUTC(startedAtDate)}
130130
</Typography>
131131
</>
132132
);

0 commit comments

Comments
 (0)