Skip to content

Commit 9f347d1

Browse files
committed
Format date according to designs
1 parent 0d0367c commit 9f347d1

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Contains an assortment of helper constants and functions for working with dates.
3+
*/
4+
5+
const dateWithoutYearFormatter = new Intl.DateTimeFormat('en', {
6+
month: 'short',
7+
day: 'numeric',
8+
hour: 'numeric',
9+
minute: '2-digit',
10+
});
11+
12+
const dateFormatter = new Intl.DateTimeFormat('en', {
13+
year: 'numeric',
14+
month: 'short',
15+
day: 'numeric',
16+
hour: 'numeric',
17+
minute: '2-digit',
18+
});
19+
20+
export function formatDate(value: Date): string {
21+
if (value.getFullYear() === new Date().getFullYear()) {
22+
return dateWithoutYearFormatter.format(value);
23+
}
24+
25+
return dateFormatter.format(value);
26+
}
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import * as React from 'react';
22
import styled from 'styled-components';
33
import { VSCodeLink } from '@vscode/webview-ui-toolkit/react';
4+
import { formatDate } from '../../pure/date';
45

56
type Props = {
67
completedAt?: Date | undefined;
78

89
onViewLogsClick: () => void;
910
};
1011

12+
const Container = styled.div`
13+
display: flex;
14+
flex-direction: column;
15+
gap: 0.5em;
16+
`;
17+
1118
const Icon = styled.span`
1219
font-size: 1em !important;
1320
vertical-align: text-bottom;
1421
`;
1522

16-
const ViewLogsLink = styled(VSCodeLink)`
17-
margin-top: 0.2em;
18-
`;
19-
2023
export const VariantAnalysisCompletionStats = ({
2124
completedAt,
2225
onViewLogsClick,
@@ -26,9 +29,9 @@ export const VariantAnalysisCompletionStats = ({
2629
}
2730

2831
return (
29-
<>
30-
{completedAt.toLocaleString()}
31-
<ViewLogsLink onClick={onViewLogsClick}>View logs</ViewLogsLink>
32-
</>
32+
<Container>
33+
<span>{formatDate(completedAt)}</span>
34+
<VSCodeLink onClick={onViewLogsClick}>View logs</VSCodeLink>
35+
</Container>
3336
);
3437
};

0 commit comments

Comments
 (0)