/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
extensions/amp-date-display/format.js
29 строк
799 B
Shihua Zheng
commit (#39097)
06 июн 2023, 02:37
Не верифицирован
06 июн 2023, 02:37
649e4ac
Код
Авторство
О чём код?
/** * @fileoverview Shared implementations of date formatting and variable * providers for Bento and Classic amp-date-display. * TODO(alanorozco): Include getVariablesInUTC and getVariablesInLocal. */ /** * @param {!Date} date * @param {string} locale * @param {?{[key: string]: *}} options * @param {string=} format ('long' by default) * @return {string} * @private */ export function getTimeZoneName(date, locale, options, format = 'long') { if (!Intl?.DateTimeFormat) { return ''; } const formatter = new Intl.DateTimeFormat(locale, { timeZone: options?.timeZone, timeZoneName: format, }); const parts = formatter.formatToParts?.(date) || []; for (const part of parts) { if (part.type === 'timeZoneName') { return part.value; } } return ''; }