UNPKG

@blueprintjs/datetime

Version:

Components for interacting with dates and times

71 lines 2.82 kB
"use strict"; /* * Copyright 2022 Palantir Technologies, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.formatTimezone = exports.TimezoneDisplayFormat = void 0; exports.TimezoneDisplayFormat = { /** * Short name format: "HST", "EDT", etc. * Falls back to "GMT+/-offset" if there is no commonly used abbreviation. */ ABBREVIATION: "abbreviation", /** * IANA timezone code: "Pacific/Honolulu", "America/New_York", etc. */ CODE: "code", /** * Composite format: "Hawaii Time (HST) -10:00", "New York (EDT) -5:00", etc. * Omits abbreviation if there is no short name (it is redundant with offset). */ COMPOSITE: "composite", /** * Long name format: "Hawaii-Aleutian Standard Time", "Eastern Daylight Time", "Coordinated Universal Time", etc. */ LONG_NAME: "long-name", /** * Offset format: "-10:00", "-5:00", etc. */ OFFSET: "offset", }; /** * Formats a timezone according to the specified display format to show in the default `<Button>` rendered as the * `<TimezoneSelect>` target element. */ function formatTimezone(timezone, displayFormat) { if (timezone === undefined) { return undefined; } switch (displayFormat) { case exports.TimezoneDisplayFormat.ABBREVIATION: return timezone.shortName; case exports.TimezoneDisplayFormat.OFFSET: return timezone.offset; case exports.TimezoneDisplayFormat.CODE: return timezone.ianaCode; case exports.TimezoneDisplayFormat.LONG_NAME: return timezone.longName; case exports.TimezoneDisplayFormat.COMPOSITE: var shortName = timezone.shortName; // if the short name is just an offset (contains + or -) or equal to the label, omit it return /[-\+]/.test(shortName) || shortName === timezone.label ? "".concat(timezone.label, " ").concat(timezone.offset) : "".concat(timezone.label, " (").concat(timezone.shortName, ") ").concat(timezone.offset); default: return undefined; } } exports.formatTimezone = formatTimezone; //# sourceMappingURL=timezoneDisplayFormat.js.map