Skip to content

Commit eeeef2a

Browse files
authored
feat: support new s/S timestamp styles in v14 (#11268)
1 parent ccbe071 commit eeeef2a

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

packages/formatters/__tests__/formatters.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,18 @@ describe('Message formatters', () => {
331331
expect<'<t:1867424897:d>'>(time(1_867_424_897, 'd')).toEqual('<t:1867424897:d>');
332332
});
333333

334-
test('GIVEN a date and a format from enum THEN returns "<t:${time}:${style}>"', () => {
335-
expect<'<t:1867424897:R>'>(time(1_867_424_897, TimestampStyles.RelativeTime)).toEqual('<t:1867424897:R>');
334+
test.each([
335+
[TimestampStyles.ShortTime, 't'],
336+
[TimestampStyles.MediumTime, 'T'],
337+
[TimestampStyles.ShortDate, 'd'],
338+
[TimestampStyles.LongDate, 'D'],
339+
[TimestampStyles.LongDateShortTime, 'f'],
340+
[TimestampStyles.FullDateShortTime, 'F'],
341+
[TimestampStyles.ShortDateShortTime, 's'],
342+
[TimestampStyles.ShortDateMediumTime, 'S'],
343+
[TimestampStyles.RelativeTime, 'R'],
344+
])('GIVEN a date and style from enum THEN returns "<t:${time}:${style}>"', (style, expectedStyle) => {
345+
expect<`<t:1867424897:${typeof style}>`>(time(1_867_424_897, style)).toEqual(`<t:1867424897:${expectedStyle}>`);
336346
});
337347
});
338348

packages/formatters/src/formatters.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,18 @@ export const TimestampStyles = {
734734
*/
735735
ShortTime: 't',
736736

737+
/**
738+
* Medium time format, consisting of hours, minutes, and seconds.
739+
*
740+
* @example `16:20:30`
741+
*/
742+
MediumTime: 'T',
743+
737744
/**
738745
* Long time format, consisting of hours, minutes, and seconds.
739746
*
740747
* @example `16:20:30`
748+
* @deprecated Use {@link TimestampStyles.MediumTime} instead.
741749
*/
742750
LongTime: 'T',
743751

@@ -751,24 +759,54 @@ export const TimestampStyles = {
751759
/**
752760
* Long date format, consisting of day, month, and year.
753761
*
754-
* @example `20 April 2021`
762+
* @example `April 20, 2021`
755763
*/
756764
LongDate: 'D',
757765

766+
/**
767+
* Long date-short time format, consisting of long date and short time.
768+
*
769+
* @example `April 20, 2021 at 16:20`
770+
*/
771+
LongDateShortTime: 'f',
772+
758773
/**
759774
* Short date-time format, consisting of short date and short time formats.
760775
*
761776
* @example `20 April 2021 16:20`
777+
* @deprecated Use {@link TimestampStyles.LongDateShortTime} instead.
762778
*/
763779
ShortDateTime: 'f',
764780

781+
/**
782+
* Full date-short time format, consisting of full date and short time.
783+
*
784+
* @example `Tuesday, April 20, 2021 at 16:20`
785+
*/
786+
FullDateShortTime: 'F',
787+
765788
/**
766789
* Long date-time format, consisting of long date and short time formats.
767790
*
768791
* @example `Tuesday, 20 April 2021 16:20`
792+
* @deprecated Use {@link TimestampStyles.FullDateShortTime} instead.
769793
*/
770794
LongDateTime: 'F',
771795

796+
/**
797+
* Short date, short time format, consisting of short date and short time.
798+
*
799+
* @example `20/04/2021, 16:20`
800+
*/
801+
ShortDateShortTime: 's',
802+
803+
/**
804+
* Short date, medium time format, consisting of short date and medium time.
805+
*
806+
* @example `20/04/2021, 16:20:30`
807+
*/
808+
ShortDateMediumTime: 'S',
809+
772810
/**
773811
* Relative time format, consisting of a relative duration format.
774812
*

0 commit comments

Comments
 (0)