Skip to content

Function.resolveDateTimeFormat

connor-baer edited this page Oct 11, 2024 · 35 revisions

@sumup-oss/intl / resolveDateTimeFormat

Function: resolveDateTimeFormat()

resolveDateTimeFormat(locales?, options?): null | ResolvedDateTimeFormatOptions

Resolves the locale and collation options that are used to format a Date.

Parameters

Parameter Type
locales? string | string[]
options? DateTimeFormatOptions

Returns

null | ResolvedDateTimeFormatOptions

Example

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

resolveDateTimeFormat();
// {
//   'locale': 'en-DE',
//   'calendar': 'gregory',
//   'numberingSystem': 'latn',
//   'timeZone': 'Europe/Berlin',
//   'year': 'numeric',
//   'month': '2-digit',
//   'day': '2-digit'
// }
resolveDateTimeFormat(['ban', 'id']);
// {
//   'locale': 'id',
//   'calendar': 'gregory',
//   'numberingSystem': 'latn',
//   'timeZone': 'Europe/Berlin',
//   'year': 'numeric',
//   'month': 'numeric',
//   'day': 'numeric'
// }
resolveDateTimeFormat('en-GB', {
  year: 'numeric',
  month: 'short',
  day: 'numeric',
});
// {
//   'locale': 'en-GB',
//   'calendar': 'gregory',
//   'numberingSystem': 'latn',
//   'timeZone': 'Europe/Berlin',
//   'year': 'numeric',
//   'month': 'short',
//   'day': 'numeric'
// }

Remarks

In runtimes that don't support the Intl.DateTimeFormat.resolvedOptions API, null is returned.

Defined in

lib/date-time-format/index.ts:283