MCPcopy Index your code
hub / github.com/formatjs/formatjs / defaultTimezone

Function defaultTimezone

packages/utils/defaultTimezone.ts:37–58  ·  view source on GitHub ↗
(
  locales?: DTFParameters[0],
  options?: Pick<Intl.DateTimeFormatOptions, 'timeZoneName'>
)

Source from the content-addressed store, hash-verified

35 * @returns default timezone for the system
36 */
37export function defaultTimezone(
38 locales?: DTFParameters[0],
39 options?: Pick<Intl.DateTimeFormatOptions, 'timeZoneName'>
40): string {
41 const timeZoneName = options?.timeZoneName
42 try {
43 const dtf = getDateTimeFormat(locales, {
44 timeZoneName: options?.timeZoneName,
45 })
46 // If there's no `timeZoneName` specified, return the IANA timezone name
47 if (!timeZoneName) {
48 return dtf.resolvedOptions().timeZone
49 }
50 // If `timeZoneName` is specified, return the localized timezone name
51 return (
52 dtf.formatToParts(now).find(p => p.type === 'timeZoneName')?.value ||
53 'UTC'
54 )
55 } catch {
56 return 'UTC'
57 }
58}

Callers 1

Calls 3

getDateTimeFormatFunction · 0.85
resolvedOptionsMethod · 0.65
formatToPartsMethod · 0.65

Tested by

no test coverage detected