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

@sumup-oss/intl / formatDateTimeRange

Variable: formatDateTimeRange

const formatDateTimeRange: (startDate, endDate, locales?, options?) => string

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

Formats a datetime range 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

string

Example

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

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

formatDateTimeRange(startDate, endDate, 'de-DE');
// 01.–29.02.2000

Remarks

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