Intl.DateTimeFormatRangePart

interface ยท experimental

interface Intl.DateTimeFormatRangePart

Represents a part of a formatted date range produced by Intl.DateTimeFormat.formatRange().

Each part has a type and value that describes its role within the formatted string. The source property indicates whether the part comes from the start date, end date, or is shared between them.

Example

const dtf = new Intl.DateTimeFormat('en', {
  dateStyle: 'long',
  timeStyle: 'short'
});
const parts = dtf.formatRangeToParts(
  new Date(2023, 0, 1, 12, 0),
  new Date(2023, 0, 3, 15, 30)
);
console.log(parts);
// Parts might include elements like:
// { type: 'month', value: 'January', source: 'startRange' }
// { type: 'day', value: '1', source: 'startRange' }
// { type: 'literal', value: ' - ', source: 'shared' }
// { type: 'day', value: '3', source: 'endRange' }
// ...

Properties

type

type: string

The type of date or time component this part represents. Possible values: 'day', 'dayPeriod', 'era', 'fractionalSecond', 'hour', 'literal', 'minute', 'month', 'relatedYear', 'second', 'timeZoneName', 'weekday', 'year', etc.

value

value: string

The string value of this part.

source

source: "shared" | "startRange" | "endRange"

Indicates which date in the range this part comes from.

  • 'startRange': The part is from the start date
  • 'endRange': The part is from the end date
  • 'shared': The part is shared between both dates (like separators)