1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

feat: feature metrics table timezone (#5880)

This commit is contained in:
Mateusz Kwasniewski 2024-01-15 15:31:10 +01:00 committed by GitHub
parent 9ac8a466ab
commit 6cfb7b4fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 4 deletions

View File

@ -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<IDateTimeCellProps> = ({ value }) => {
export const DateTimeCell: VFC<IDateTimeCellProps> = ({ 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 <TextCell lineClamp={1}>{date}</TextCell>;

View File

@ -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(
<FeatureMetricsTable
metrics={[
{
featureName: 'irrelevant',
appName: 'my-application',
environment: 'development',
yes: 20,
no: 10,
timestamp: '2024-01-12T12:00:00.000Z',
},
]}
/>,
);
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(
<FeatureMetricsTable
metrics={[
{
featureName: 'irrelevant',
appName: 'my-application',
environment: 'development',
yes: 20,
no: 10,
timestamp: '2024-01-12T23:59:59.999Z',
},
]}
/>,
);
// 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();
});

View File

@ -90,7 +90,14 @@ const COLUMNS = [
Header: 'Time',
accessor: 'timestamp',
Cell: (props: any) => (
<DateTimeCell value={props.row.original.timestamp} />
<DateTimeCell
value={props.row.original.timestamp}
timeZone={
props.row.original.timestamp.includes('23:59')
? 'UTC'
: undefined
}
/>
),
},
{