@wordpress/components
Version:
UI components for WordPress.
36 lines (35 loc) • 1.46 kB
JavaScript
import { __ } from "@wordpress/i18n";
import { getSettings as getDateSettings } from "@wordpress/date";
import Tooltip from "../../tooltip";
import { TimeZone as StyledComponent } from "./styles";
import { jsx as _jsx } from "react/jsx-runtime";
const TimeZone = () => {
const {
timezone
} = getDateSettings();
const userTimezoneOffset = -1 * ((/* @__PURE__ */ new Date()).getTimezoneOffset() / 60);
if (Number(timezone.offset) === userTimezoneOffset) {
return null;
}
const offsetSymbol = Number(timezone.offset) >= 0 ? "+" : "";
const zoneAbbr = "" !== timezone.abbr && isNaN(Number(timezone.abbr)) ? timezone.abbr : `UTC${offsetSymbol}${timezone.offsetFormatted}`;
const prettyTimezoneString = timezone.string.replace("_", " ");
const timezoneDetail = "UTC" === timezone.string ? __("Coordinated Universal Time") : `(${zoneAbbr}) ${prettyTimezoneString}`;
const hasNoAdditionalTimezoneDetail = prettyTimezoneString.trim().length === 0;
return hasNoAdditionalTimezoneDetail ? /* @__PURE__ */ _jsx(StyledComponent, {
className: "components-datetime__timezone",
children: zoneAbbr
}) : /* @__PURE__ */ _jsx(Tooltip, {
placement: "top",
text: timezoneDetail,
children: /* @__PURE__ */ _jsx(StyledComponent, {
className: "components-datetime__timezone",
children: zoneAbbr
})
});
};
var timezone_default = TimeZone;
export {
timezone_default as default
};
//# sourceMappingURL=timezone.js.map