( locales?: DTFParameters[0], options?: Pick<Intl.DateTimeFormatOptions, 'timeZoneName'> )
| 35 | * @returns default timezone for the system |
| 36 | */ |
| 37 | export 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 | } |
no test coverage detected