Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(date): Default show datetime in local timezone instead of UTC #855

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions packages/oss-console/src/common/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@

const defaultUTCFormat = 'l LTS';

/** Formats a date into a standard string with a moment-style "from now" hint
* ex. 12/21/2017 8:19:36 PM (18 days ago)
*/
export function dateWithFromNow(input: Date) {
if (!isValidDate(input)) {
return unknownValueString;
}

const date = moment.utc(input);
return `${date.format(defaultUTCFormat)} UTC (${date.fromNow()})`;
}

/** Formats a date into a moment-style "from now" value */
export function dateFromNow(input: Date) {
if (!isValidDate(input)) {
Expand Down Expand Up @@ -51,7 +39,7 @@
/**
* Gets human-readable date relative to "now"
*/
export function formateDateRelative(input: Date, threshold = 24 * 60 * 60 * 1000) {
export function formatDateRelative(input: Date, threshold = 24 * 60 * 60 * 1000) {
if (!isValidDate(input)) {
return unknownValueString;
}
Expand All @@ -72,6 +60,18 @@
return isValidDate(input) ? moment(input).tz(timezone).format('l LTS z') : unknownValueString;
}

/** Formats a date into a standard string with a moment-style "from now" hint
* ex. 12/21/2017 8:19:36 PM (18 days ago)
*/
export function dateWithFromNow(input: Date) {
if (!isValidDate(input)) {
return unknownValueString;

Check warning on line 68 in packages/oss-console/src/common/formatters.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L68 was not covered by tests
}

const date = moment.utc(input);
return `${formatDateLocalTimezone(input)} (${date.fromNow()})`;
}

/** Outputs a value in milliseconds in (H M S) format (ex. 2h 3m 30s) */
export function millisecondsToHMS(valueMS: number): string {
if (valueMS < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Link as RouterLink } from 'react-router-dom';
import styled from '@mui/system/styled';
import * as CommonStylesConstants from '@clients/theme/CommonStyles/constants';
import { dashedValueString } from '@clients/common/constants';
import { formatDateUTC, protobufDurationToHMS } from '../../../common/formatters';
import { formatDateLocalTimezone, protobufDurationToHMS } from '../../../common/formatters';
import { timestampToDate } from '../../../common/utils';
import { useCommonStyles } from '../../common/styles';
import { Routes } from '../../../routes/routes';
Expand Down Expand Up @@ -85,7 +85,7 @@ export const ExecutionMetadata: React.FC<{}> = () => {
},
{
label: ExecutionMetadataLabels.time,
value: startedAt ? formatDateUTC(timestampToDate(startedAt)) : dashedValueString,
value: startedAt ? formatDateLocalTimezone(timestampToDate(startedAt)) : dashedValueString,
},
{
label: ExecutionMetadataLabels.duration,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ResourceType } from '../../../models/Common/types';
import { Execution, NodeExecution, TaskExecution } from '../../../models/Execution/types';
import { timestampToDate } from '../../../common/utils';
import { formatDateUTC } from '../../../common/formatters';
import { formatDateLocalTimezone } from '../../../common/formatters';

export function isSingleTaskExecution(execution: Execution) {
return execution.spec.launchPlan.resourceType === ResourceType.TASK;
Expand All @@ -21,8 +21,9 @@
reasons = reasons.concat(
finalReasons.map(
(reason) =>
(reason.occurredAt ? `${formatDateUTC(timestampToDate(reason.occurredAt))} ` : '') +
reason.message,
(reason.occurredAt
? `${formatDateLocalTimezone(timestampToDate(reason.occurredAt))} `
: '') + reason.message,

Check warning on line 26 in packages/oss-console/src/components/Executions/ExecutionDetails/utils.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L24 - L26 were not covered by tests
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,16 @@ export const NodeExecutionsTable: React.FC<{
</TableHead>
<TableBody>
{showNodes.length > 0 ? (
showNodes.map((node) => {
return (
<NodeExecutionDynamicProvider node={node} key={node.scopedId}>
<NodeExecutionRow
columns={columns}
node={node}
onToggle={toggleNode}
key={node.scopedId}
/>
</NodeExecutionDynamicProvider>
);
})
showNodes.map((node) => (
<NodeExecutionDynamicProvider node={node} key={node.scopedId}>
<NodeExecutionRow
columns={columns}
node={node}
onToggle={toggleNode}
key={node.scopedId}
/>
</NodeExecutionDynamicProvider>
))
) : (
<TableNoRowsCell displayMessage={noExecutionsFoundString} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import {
formatDateLocalTimezone,
formatDateUTC,
formateDateRelative,
formatDateRelative,
millisecondsToHMS,
} from '../../../../common/formatters';
import { timestampToDate } from '../../../../common/utils';
Expand Down Expand Up @@ -83,7 +83,7 @@
// const isArchived = isExecutionArchived(execution);

if (isRelativeStartTime) {
return formateDateRelative(startedAtDate);
return formatDateRelative(startedAtDate);

Check warning on line 86 in packages/oss-console/src/components/Executions/Tables/WorkflowExecutionTable/cells.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L86 was not covered by tests
}

const localTime = React.useMemo(() => {
Expand Down Expand Up @@ -113,8 +113,8 @@
}
return `${h}h ${m}m ago`;
}
return utc;
}, [startedAtDate, utc]);
return localTime;

Check warning on line 116 in packages/oss-console/src/components/Executions/Tables/WorkflowExecutionTable/cells.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L116 was not covered by tests
}, [startedAtDate, localTime]);

const tooltipText = React.useMemo(() => {
const isLast24Hours = moment().diff(startedAtDate, 'hours') < 24;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ export function generateColumns(
return (
<>
<Typography variant="body1" className={className}>
{formatDateUTC(startedAtDate)}
{formatDateLocalTimezone(startedAtDate)}
</Typography>
<Typography variant="subtitle1" color="textSecondary" className={className}>
{formatDateLocalTimezone(startedAtDate)}
{formatDateUTC(startedAtDate)}
</Typography>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { render } from '@testing-library/react';
import * as React from 'react';
import moment from 'moment-timezone';
import { ThemeProvider } from '@mui/material/styles';
import { muiTheme } from '@clients/theme/Theme/muiTheme';
import { timezone } from '@clients/oss-console/common/timezone';
import { unknownValueString } from '@clients/common/constants';
import { long } from '../../../../test/utils';
import { TaskExecutionDetails } from '../TaskExecutionDetails';

const date = { seconds: long(5), nanos: 0 };
const duration = { seconds: long(0), nanos: 0 };

const dateContent = '1/1/1970 12:00:05 AM UTC';
const utcDateContent = '1/1/1970 12:00:05 AM UTC';
const dateContent = moment(utcDateContent).tz(timezone).format('l LTS z');

describe('TaskExecutionDetails', () => {
it('should render details with task started info and duration', () => {
Expand Down
Loading