Skip to content

Commit e8217e3

Browse files
authored
feat!: support new s/S timestamp styles (#11267)
BREAKING CHANGE: `TimestampStyles.LongTime` has been removed. Use `TimestampStyles.MediumTime` instead. BREAKING CHANGE: `TimestampStyles.ShortDateTime` has been removed. Use `TimestampStyles.LongDateShortTime` instead. BREAKING CHANGE: `TimestampStyles.LongDateTime` has been removed. Use `TimestampStyles.FullDateShortTime` instead.
1 parent 538b47d commit e8217e3

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
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: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -725,11 +725,11 @@ export const TimestampStyles = {
725725
ShortTime: 't',
726726

727727
/**
728-
* Long time format, consisting of hours, minutes, and seconds.
728+
* Medium time format, consisting of hours, minutes, and seconds.
729729
*
730730
* @example `16:20:30`
731731
*/
732-
LongTime: 'T',
732+
MediumTime: 'T',
733733

734734
/**
735735
* Short date format, consisting of day, month, and year.
@@ -741,23 +741,37 @@ export const TimestampStyles = {
741741
/**
742742
* Long date format, consisting of day, month, and year.
743743
*
744-
* @example `20 April 2021`
744+
* @example `April 20, 2021`
745745
*/
746746
LongDate: 'D',
747747

748748
/**
749-
* Short date-time format, consisting of short date and short time formats.
749+
* Long date-short time format, consisting of long date and short time.
750750
*
751-
* @example `20 April 2021 16:20`
751+
* @example `April 20, 2021 at 16:20`
752752
*/
753-
ShortDateTime: 'f',
753+
LongDateShortTime: 'f',
754754

755755
/**
756-
* Long date-time format, consisting of long date and short time formats.
756+
* Full date-short time format, consisting of full date and short time.
757757
*
758-
* @example `Tuesday, 20 April 2021 16:20`
758+
* @example `Tuesday, April 20, 2021 at 16:20`
759759
*/
760-
LongDateTime: 'F',
760+
FullDateShortTime: 'F',
761+
762+
/**
763+
* Short date, short time format, consisting of short date and short time.
764+
*
765+
* @example `20/04/2021, 16:20`
766+
*/
767+
ShortDateShortTime: 's',
768+
769+
/**
770+
* Short date, medium time format, consisting of short date and medium time.
771+
*
772+
* @example `20/04/2021, 16:20:30`
773+
*/
774+
ShortDateMediumTime: 'S',
761775

762776
/**
763777
* Relative time format, consisting of a relative duration format.

0 commit comments

Comments
 (0)