diff --git a/frontend/src/component/common/Table/cells/DateTimeCell/DateTimeCell.tsx b/frontend/src/component/common/Table/cells/DateTimeCell/DateTimeCell.tsx index f6d8bc0c65..174651ef42 100644 --- a/frontend/src/component/common/Table/cells/DateTimeCell/DateTimeCell.tsx +++ b/frontend/src/component/common/Table/cells/DateTimeCell/DateTimeCell.tsx @@ -6,15 +6,20 @@ import { TextCell } from 'component/common/Table/cells/TextCell/TextCell'; interface IDateTimeCellProps { value?: Date | string | null; + timeZone?: string; } -export const DateTimeCell: VFC = ({ value }) => { +export const DateTimeCell: VFC = ({ value, timeZone }) => { const { locationSettings } = useLocationSettings(); const date = value ? value instanceof Date - ? formatDateYMDHM(value, locationSettings.locale) - : formatDateYMDHM(parseISO(value), locationSettings.locale) + ? formatDateYMDHM(value, locationSettings.locale, timeZone) + : formatDateYMDHM( + parseISO(value), + locationSettings.locale, + timeZone, + ) : undefined; return {date}; diff --git a/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.test.tsx b/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.test.tsx new file mode 100644 index 0000000000..0e00635cfb --- /dev/null +++ b/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.test.tsx @@ -0,0 +1,57 @@ +import { render } from 'utils/testRenderer'; +import { FeatureMetricsTable } from './FeatureMetricsTable'; +import { screen } from '@testing-library/react'; +import { formatDateYMDHM } from '../../../../../utils/formatDate'; + +test('render local time for hourly results', async () => { + render( + , + ); + const localDate = formatDateYMDHM('2024-01-12T12:00:00.000Z', 'en-US'); + + expect(screen.getByText('my-application')).toBeInTheDocument(); + expect(screen.getByText('development')).toBeInTheDocument(); + expect(screen.getByText('30')).toBeInTheDocument(); + expect(screen.getByText('20')).toBeInTheDocument(); + expect(screen.getByText(localDate)).toBeInTheDocument(); +}); + +test('render UTC for daily results', async () => { + render( + , + ); + // 23:59 is hour UTC heuristic + const localDate = formatDateYMDHM( + '2024-01-12T23:59:59.999Z', + 'en-US', + 'UTC', + ); + + expect(screen.getByText('my-application')).toBeInTheDocument(); + expect(screen.getByText('development')).toBeInTheDocument(); + expect(screen.getByText('30')).toBeInTheDocument(); + expect(screen.getByText('20')).toBeInTheDocument(); + expect(screen.getByText(localDate)).toBeInTheDocument(); +}); diff --git a/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.tsx b/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.tsx index bce31bf469..be18ce1a1a 100644 --- a/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureMetrics/FeatureMetricsTable/FeatureMetricsTable.tsx @@ -90,7 +90,14 @@ const COLUMNS = [ Header: 'Time', accessor: 'timestamp', Cell: (props: any) => ( - + ), }, {