@gechiui/components
Version:
UI components for GeChiUI.
41 lines (34 loc) • 1.29 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* GeChiUI dependencies
*/
import { __ } from '@gechiui/i18n';
import { __experimentalGetSettings as getDateSettings } from '@gechiui/date';
/**
* Internal dependencies
*/
import Tooltip from '../tooltip';
/**
* Displays timezone information when user timezone is different from site timezone.
*/
const TimeZone = () => {
const {
timezone
} = getDateSettings(); // Convert timezone offset to hours.
const userTimezoneOffset = -1 * (new Date().getTimezoneOffset() / 60); // System timezone and user timezone match, nothing needed.
// Compare as numbers because it comes over as string.
if (Number(timezone.offset) === userTimezoneOffset) {
return null;
}
const offsetSymbol = timezone.offset >= 0 ? '+' : '';
const zoneAbbr = '' !== timezone.abbr && isNaN(timezone.abbr) ? timezone.abbr : `UTC${offsetSymbol}${timezone.offset}`;
const timezoneDetail = 'UTC' === timezone.string ? __('协调世界时') : `(${zoneAbbr}) ${timezone.string.replace('_', ' ')}`;
return createElement(Tooltip, {
position: "top center",
text: timezoneDetail
}, createElement("div", {
className: "components-datetime__timezone"
}, zoneAbbr));
};
export default TimeZone;
//# sourceMappingURL=timezone.js.map