UNPKG

@wordpress/components

Version:
8 lines (7 loc) 2.87 kB
{ "version": 3, "sources": ["../../../src/date-time/time/timezone.tsx"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { getSettings as getDateSettings } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport Tooltip from '../../tooltip';\nimport { TimeZone as StyledComponent } from './styles';\n\n/**\n * Displays timezone information when user timezone is different from site\n * timezone.\n */\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nconst TimeZone = () => {\n const {\n timezone\n } = getDateSettings();\n\n // Convert timezone offset to hours.\n const userTimezoneOffset = -1 * (new Date().getTimezoneOffset() / 60);\n\n // System timezone and user timezone match, nothing needed.\n // Compare as numbers because it comes over as string.\n if (Number(timezone.offset) === userTimezoneOffset) {\n return null;\n }\n const offsetSymbol = Number(timezone.offset) >= 0 ? '+' : '';\n const zoneAbbr = '' !== timezone.abbr && isNaN(Number(timezone.abbr)) ? timezone.abbr : `UTC${offsetSymbol}${timezone.offsetFormatted}`;\n\n // Replace underscore with space in strings like `America/Costa_Rica`.\n const prettyTimezoneString = timezone.string.replace('_', ' ');\n const timezoneDetail = 'UTC' === timezone.string ? __('Coordinated Universal Time') : `(${zoneAbbr}) ${prettyTimezoneString}`;\n\n // When the prettyTimezoneString is empty, there is no additional timezone\n // detail information to show in a Tooltip.\n const hasNoAdditionalTimezoneDetail = prettyTimezoneString.trim().length === 0;\n return hasNoAdditionalTimezoneDetail ? /*#__PURE__*/_jsx(StyledComponent, {\n className: \"components-datetime__timezone\",\n children: zoneAbbr\n }) : /*#__PURE__*/_jsx(Tooltip, {\n placement: \"top\",\n text: timezoneDetail,\n children: /*#__PURE__*/_jsx(StyledComponent, {\n className: \"components-datetime__timezone\",\n children: zoneAbbr\n })\n });\n};\nexport default TimeZone;"], "mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,eAAe,uBAAuB;AAK/C,OAAO,aAAa;AACpB,SAAS,YAAY,uBAAuB;AAM5C,SAAS,OAAO,YAAY;AAC5B,IAAM,WAAW,MAAM;AACrB,QAAM;AAAA,IACJ;AAAA,EACF,IAAI,gBAAgB;AAGpB,QAAM,qBAAqB,OAAM,oBAAI,KAAK,GAAE,kBAAkB,IAAI;AAIlE,MAAI,OAAO,SAAS,MAAM,MAAM,oBAAoB;AAClD,WAAO;AAAA,EACT;AACA,QAAM,eAAe,OAAO,SAAS,MAAM,KAAK,IAAI,MAAM;AAC1D,QAAM,WAAW,OAAO,SAAS,QAAQ,MAAM,OAAO,SAAS,IAAI,CAAC,IAAI,SAAS,OAAO,MAAM,YAAY,GAAG,SAAS,eAAe;AAGrI,QAAM,uBAAuB,SAAS,OAAO,QAAQ,KAAK,GAAG;AAC7D,QAAM,iBAAiB,UAAU,SAAS,SAAS,GAAG,4BAA4B,IAAI,IAAI,QAAQ,KAAK,oBAAoB;AAI3H,QAAM,gCAAgC,qBAAqB,KAAK,EAAE,WAAW;AAC7E,SAAO,gCAA6C,qBAAK,iBAAiB;AAAA,IACxE,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,CAAC,IAAiB,qBAAK,SAAS;AAAA,IAC9B,WAAW;AAAA,IACX,MAAM;AAAA,IACN,UAAuB,qBAAK,iBAAiB;AAAA,MAC3C,WAAW;AAAA,MACX,UAAU;AAAA,IACZ,CAAC;AAAA,EACH,CAAC;AACH;AACA,IAAO,mBAAQ;", "names": [] }