feat: support new s/S timestamp styles in v14 (#11268)

This commit is contained in:
Danial Raza
2025-11-12 11:56:02 +01:00
committed by GitHub
parent ccbe0716a4
commit eeeef2ac50
2 changed files with 51 additions and 3 deletions

View File

@@ -331,8 +331,18 @@ describe('Message formatters', () => {
expect<'<t:1867424897:d>'>(time(1_867_424_897, 'd')).toEqual('<t:1867424897:d>');
});
test('GIVEN a date and a format from enum THEN returns "<t:${time}:${style}>"', () => {
expect<'<t:1867424897:R>'>(time(1_867_424_897, TimestampStyles.RelativeTime)).toEqual('<t:1867424897:R>');
test.each([
[TimestampStyles.ShortTime, 't'],
[TimestampStyles.MediumTime, 'T'],
[TimestampStyles.ShortDate, 'd'],
[TimestampStyles.LongDate, 'D'],
[TimestampStyles.LongDateShortTime, 'f'],
[TimestampStyles.FullDateShortTime, 'F'],
[TimestampStyles.ShortDateShortTime, 's'],
[TimestampStyles.ShortDateMediumTime, 'S'],
[TimestampStyles.RelativeTime, 'R'],
])('GIVEN a date and style from enum THEN returns "<t:${time}:${style}>"', (style, expectedStyle) => {
expect<`<t:1867424897:${typeof style}>`>(time(1_867_424_897, style)).toEqual(`<t:1867424897:${expectedStyle}>`);
});
});

View File

@@ -734,10 +734,18 @@ export const TimestampStyles = {
*/
ShortTime: 't',
/**
* Medium time format, consisting of hours, minutes, and seconds.
*
* @example `16:20:30`
*/
MediumTime: 'T',
/**
* Long time format, consisting of hours, minutes, and seconds.
*
* @example `16:20:30`
* @deprecated Use {@link TimestampStyles.MediumTime} instead.
*/
LongTime: 'T',
@@ -751,24 +759,54 @@ export const TimestampStyles = {
/**
* Long date format, consisting of day, month, and year.
*
* @example `20 April 2021`
* @example `April 20, 2021`
*/
LongDate: 'D',
/**
* Long date-short time format, consisting of long date and short time.
*
* @example `April 20, 2021 at 16:20`
*/
LongDateShortTime: 'f',
/**
* Short date-time format, consisting of short date and short time formats.
*
* @example `20 April 2021 16:20`
* @deprecated Use {@link TimestampStyles.LongDateShortTime} instead.
*/
ShortDateTime: 'f',
/**
* Full date-short time format, consisting of full date and short time.
*
* @example `Tuesday, April 20, 2021 at 16:20`
*/
FullDateShortTime: 'F',
/**
* Long date-time format, consisting of long date and short time formats.
*
* @example `Tuesday, 20 April 2021 16:20`
* @deprecated Use {@link TimestampStyles.FullDateShortTime} instead.
*/
LongDateTime: 'F',
/**
* Short date, short time format, consisting of short date and short time.
*
* @example `20/04/2021, 16:20`
*/
ShortDateShortTime: 's',
/**
* Short date, medium time format, consisting of short date and medium time.
*
* @example `20/04/2021, 16:20:30`
*/
ShortDateMediumTime: 'S',
/**
* Relative time format, consisting of a relative duration format.
*