Skip to content

Commit 1e4855b

Browse files
committed
ARTESCA-14587: Add new dateformate for chart xaxis tick and chart tooltip title
1 parent 468afd0 commit 1e4855b

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

src/lib/components/date/FormattedDateTime.spec.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,28 @@ describe('FormatttedDateTime', () => {
214214
//V
215215
expect(screen.getByText('2022-12-12 11:57:26')).toBeInTheDocument();
216216
});
217+
218+
it('should display the date in the expected format of the xaxis tick in the chart', () => {
219+
//S
220+
render(
221+
<FormattedDateTime
222+
format="day-month-abbreviated-hour-minute"
223+
value={new Date('2022-10-06T18:33:00Z')}
224+
/>,
225+
);
226+
//V
227+
expect(screen.getByText('6 Oct 18:33')).toBeInTheDocument();
228+
});
229+
230+
it('should display the date in the expected format of date in the chart', () => {
231+
//S
232+
render(
233+
<FormattedDateTime
234+
format="day-month-abbreviated-hour-minute-second"
235+
value={new Date('2022-10-06T18:33:00Z')}
236+
/>,
237+
);
238+
//V
239+
expect(screen.getByText('6 Oct 18:33:00')).toBeInTheDocument();
240+
});
217241
});

src/lib/components/date/FormattedDateTime.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,36 @@ export const TIME_FORMATER = Intl.DateTimeFormat('en-GB', {
2121
minute: '2-digit',
2222
});
2323

24+
export const DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND = Intl.DateTimeFormat(
25+
'en-GB',
26+
{
27+
day: 'numeric',
28+
month: 'short',
29+
hour: '2-digit',
30+
minute: '2-digit',
31+
second: '2-digit',
32+
hour12: false,
33+
},
34+
);
35+
36+
export const DAY_MONTH_ABBREVIATED_HOUR_MINUTE = Intl.DateTimeFormat('en-GB', {
37+
day: 'numeric',
38+
month: 'short',
39+
hour: '2-digit',
40+
minute: '2-digit',
41+
hour12: false,
42+
});
43+
2444
type FormattedDateTimeProps = {
2545
format:
2646
| 'date'
2747
| 'date-time'
2848
| 'date-time-second'
2949
| 'time'
3050
| 'time-second'
31-
| 'relative';
51+
| 'relative'
52+
| 'day-month-abbreviated-hour-minute'
53+
| 'day-month-abbreviated-hour-minute-second';
3254
value: Date;
3355
};
3456

@@ -143,7 +165,19 @@ export const FormattedDateTime = ({
143165
few seconds ago
144166
</Tooltip>
145167
);
146-
//TO FINISH
168+
case 'day-month-abbreviated-hour-minute':
169+
return (
170+
<>{DAY_MONTH_ABBREVIATED_HOUR_MINUTE.format(value).replace(',', '')}</>
171+
);
172+
case 'day-month-abbreviated-hour-minute-second':
173+
return (
174+
<>
175+
{DAY_MONTH_ABBREVIATED_HOUR_MINUTE_SECOND.format(value).replace(
176+
',',
177+
'',
178+
)}
179+
</>
180+
);
147181
default:
148182
return <></>;
149183
}

stories/format.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ import { Meta } from '@storybook/blocks';
3232
| Short#1 | DD MMM | 20 Jul | 5 | Chart time axis |
3333
| Short#2 | DDMMM HH:mm | 20Jul 09:00 | 11 | Limited space, year not needed |
3434
| Short#3 | YYYY-MM-DD | 2020-07-20 | 10 | Tables |
35-
| Mid#1 | YYYY-MM-DD HH:mm | 2020-07-20 09:00 | 16 | Tables (creation/modification dates) |
36-
| Mid#2 | YYYY-MM-DD HH:mm:ss | 2020-07-20 09:00:00 | 19 | When the seconds are needed |
35+
| Mid#1 | DD MMM HH:mm | 20 Jul 09:00 | 12 | Chart Axis ticks |
36+
| Mid#2 | DD MMM HH:mm:ss | 20 Jul 09:00:00 | 15 | Chart Tooltip title |
37+
| Mid#3 | YYYY-MM-DD HH:mm | 2020-07-20 09:00 | 16 | Tables (creation/modification dates) |
38+
| Mid#4 | YYYY-MM-DD HH:mm:ss | 2020-07-20 09:00:00 | 19 | When the seconds are needed |
3739
| Full#1 | EEE MMM DD YYYY HH:mm:ss | Mon Jul 20 2020 09:00:00 | 24 | When a lot of space (hover) - When precision is needed |
3840

3941
### Remarks:

0 commit comments

Comments
 (0)