deno.com

method Intl.DateTimeFormat.formatRangeToParts

Overload 1

#DateTimeFormat.formatRangeToParts<T extends Formattable>(
startDate: T,
endDate: T,
): DateTimeFormatRangePart[]

Allow locale-aware formatting of tokens representing each part of the formatted date range produced by Intl.DateTimeFormat formatters.

Examples #

#
const formatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'long' });
const startDate = new Date(2023, 0, 1);
const endDate = new Date(2023, 0, 5);
const parts = formatter.formatRangeToParts(startDate, endDate);
console.log(parts);
// Output might include:
// [
//   { type: 'month', value: 'January', source: 'startRange' },
//   { type: 'literal', value: ' ', source: 'shared' },
//   { type: 'day', value: '1', source: 'startRange' },
//   { type: 'literal', value: ' – ', source: 'shared' },
//   { type: 'day', value: '5', source: 'endRange' },
//   { type: 'literal', value: ', ', source: 'shared' },
//   { type: 'year', value: '2023', source: 'shared' }
// ]

Type Parameters #

#T extends Formattable

Parameters #

#startDate: T

The start date of the range to format.

#endDate: T

The start date of the range to format. Must be the same type as startRange.

Return Type #

Overload 2

#DateTimeFormat.formatRangeToParts(
startDate: Date | number,
endDate: Date | number,
): DateTimeFormatRangePart[]

Parameters #

#startDate: Date | number
#endDate: Date | number

Return Type #