Variable.formatDateTimeRangeToParts - sumup-oss/intl-js GitHub Wiki

@sumup-oss/intl / formatDateTimeRangeToParts

Variable: formatDateTimeRangeToParts

const formatDateTimeRangeToParts: (startDate, endDate, locales?, options?) => (DateTimeFormatPart | { type: "date"; value: string; })[]

Defined in: lib/date-time-format/index.ts:382

Formats a datetime range to parts with support for various date and time styles.

Parameters

Parameter Type Description
startDate FormattableDateTime -
endDate FormattableDateTime -
locales? string | string[] Formatting locale. Omitting this is deprecated and will become required in a future major version. When omitted, formatting uses the runtime default (browser or server locale), which may not match your user.
options? DateTimeFormatOptions -

Returns

(DateTimeFormatPart | { type: "date"; value: string; })[]

Example

import { formatDateTimeRangeToParts } from '@sumup-oss/intl';

const startDate = new Temporal.PlainDate(2000, 2, 1);
const endDate = new Temporal.PlainDate(2000, 2, 29);

formatDateTimeRangeToParts(startDate, endDate, 'de-DE');
// [
//   {
//     "source": "startRange",
//     "type": "day",
//     "value": "01",
//   },
//   {
//     "source": "shared",
//     "type": "literal",
//     "value": ".–",
//   },
//   {
//     "source": "endRange",
//     "type": "day",
//     "value": "29",
//   },
//   {
//     "source": "shared",
//     "type": "literal",
//     "value": ".",
//   },
//   {
//     "source": "shared",
//     "type": "month",
//     "value": "02",
//   },
//   {
//     "source": "shared",
//     "type": "literal",
//     "value": ".",
//   },
//   {
//     "source": "shared",
//     "type": "year",
//     "value": "2000",
//   },
// ]

Remarks

In runtimes that don't support the Intl.DateTimeFormat.formatDateTimeRangeToParts API, the start and end dates are localized individually and joined using an en dash.