@pingux/astro 2.187.0-alpha.0 → 2.188.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/TimeZonePicker/TimeZonePicker.js +38 -8
- package/lib/cjs/components/TimeZonePicker/TimeZonePicker.stories.js +49 -1
- package/lib/cjs/components/TimeZonePicker/TimeZonePicker.test.js +155 -2
- package/lib/cjs/components/TimeZonePicker/helper.d.ts +2 -2
- package/lib/cjs/components/TimeZonePicker/helper.js +12 -6
- package/lib/cjs/components/TimeZonePicker/helper.test.js +27 -0
- package/lib/components/TimeZonePicker/TimeZonePicker.js +38 -8
- package/lib/components/TimeZonePicker/TimeZonePicker.stories.js +48 -0
- package/lib/components/TimeZonePicker/TimeZonePicker.test.js +155 -2
- package/lib/components/TimeZonePicker/helper.js +12 -6
- package/lib/components/TimeZonePicker/helper.test.js +27 -0
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ var _pendoID = require("../../utils/devUtils/constants/pendoID");
|
|
|
35
35
|
var _helper = require("./helper");
|
|
36
36
|
var _timezones = _interopRequireWildcard(require("./timezones"));
|
|
37
37
|
var _react2 = require("@emotion/react");
|
|
38
|
-
var _excluded = ["additionalTimeZones", "emptySearchText", "locales", "localeOptions", "selectedKey", "onSelectionChange", "inputValue", "onInputChange"];
|
|
38
|
+
var _excluded = ["additionalTimeZones", "emptySearchText", "items", "locales", "localeOptions", "timezoneFormat", "selectedKey", "onSelectionChange", "inputValue", "onInputChange"];
|
|
39
39
|
function _interopRequireWildcard(e, t) { if ("function" == typeof _WeakMap) var r = new _WeakMap(), n = new _WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
40
40
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty2(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
41
41
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty2(_context8 = ownKeys(Object(t), !0)).call(_context8, function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty2(_context9 = ownKeys(Object(t))).call(_context9, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -56,8 +56,10 @@ var createSearchTags = function createSearchTags(_ref) {
|
|
|
56
56
|
var TimeZonePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
57
57
|
var additionalTimeZones = props.additionalTimeZones,
|
|
58
58
|
emptySearchText = props.emptySearchText,
|
|
59
|
+
itemsProp = props.items,
|
|
59
60
|
locales = props.locales,
|
|
60
61
|
localeOptions = props.localeOptions,
|
|
62
|
+
timezoneFormat = props.timezoneFormat,
|
|
61
63
|
selectedKeyProp = props.selectedKey,
|
|
62
64
|
onSelectionChangeProp = props.onSelectionChange,
|
|
63
65
|
inputValueProp = props.inputValue,
|
|
@@ -82,13 +84,16 @@ var TimeZonePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
82
84
|
});
|
|
83
85
|
var allTimeZones = (0, _react.useMemo)(function () {
|
|
84
86
|
var _context4, _context5;
|
|
87
|
+
if (itemsProp) {
|
|
88
|
+
return itemsProp;
|
|
89
|
+
}
|
|
85
90
|
var sourceList = additionalTimeZones ? _objectSpread(_objectSpread({}, _timezones["default"]), additionalTimeZones) : _timezones["default"];
|
|
86
91
|
return (0, _sort["default"])(_context4 = (0, _map["default"])(_context5 = (0, _entries["default"])(sourceList)).call(_context5, function (_ref2) {
|
|
87
92
|
var _context6;
|
|
88
93
|
var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
|
|
89
94
|
label = _ref3[0],
|
|
90
95
|
tzValue = _ref3[1];
|
|
91
|
-
var _getGmtAndOffset = (0, _helper.getGmtAndOffset)(tzValue),
|
|
96
|
+
var _getGmtAndOffset = (0, _helper.getGmtAndOffset)(tzValue, timezoneFormat),
|
|
92
97
|
gmt = _getGmtAndOffset.gmt,
|
|
93
98
|
numericOffset = _getGmtAndOffset.numericOffset;
|
|
94
99
|
var displayTz = tzValue.replace(/_/g, ' ');
|
|
@@ -107,7 +112,7 @@ var TimeZonePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
107
112
|
})).call(_context4, function (a, b) {
|
|
108
113
|
return a.numericOffset - b.numericOffset;
|
|
109
114
|
});
|
|
110
|
-
}, [additionalTimeZones]);
|
|
115
|
+
}, [additionalTimeZones, timezoneFormat, itemsProp]);
|
|
111
116
|
|
|
112
117
|
// Sync internal input value when controlled selectedKey changes externally
|
|
113
118
|
(0, _react.useEffect)(function () {
|
|
@@ -142,9 +147,13 @@ var TimeZonePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
|
142
147
|
var now = new Date();
|
|
143
148
|
var map = new _map2["default"]();
|
|
144
149
|
(0, _forEach["default"])(allTimeZones).call(allTimeZones, function (tz) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
try {
|
|
151
|
+
map.set(tz.id, now.toLocaleTimeString(locales, _objectSpread({
|
|
152
|
+
timeZone: tz.id
|
|
153
|
+
}, localeOptions)));
|
|
154
|
+
} catch (e) {
|
|
155
|
+
map.set(tz.id, '');
|
|
156
|
+
}
|
|
148
157
|
});
|
|
149
158
|
return map;
|
|
150
159
|
}, [allTimeZones, locales, localeOptions]);
|
|
@@ -235,7 +244,27 @@ TimeZonePicker.propTypes = {
|
|
|
235
244
|
/** The current input value (controlled). */
|
|
236
245
|
inputValue: _propTypes["default"].string,
|
|
237
246
|
/** Handler called when the input value changes. */
|
|
238
|
-
onInputChange: _propTypes["default"].func
|
|
247
|
+
onInputChange: _propTypes["default"].func,
|
|
248
|
+
/**
|
|
249
|
+
* The format to use for timezone offset display.
|
|
250
|
+
* - `'gmt'` (default): Display offsets as GMT (e.g., GMT-08:00)
|
|
251
|
+
* - `'utc'`: Display offsets as UTC (e.g., UTC-08:00)
|
|
252
|
+
*/
|
|
253
|
+
timezoneFormat: _propTypes["default"].oneOf(['gmt', 'utc']),
|
|
254
|
+
/**
|
|
255
|
+
* Custom items to render instead of the default timezone list. When provided, the component
|
|
256
|
+
* uses these items directly. Each item should have the shape:
|
|
257
|
+
* `{ key: string, id: string, label: string, timeZone: string, gmt: string, numericOffset: number, searchTags: string }`
|
|
258
|
+
*/
|
|
259
|
+
items: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
260
|
+
key: _propTypes["default"].string.isRequired,
|
|
261
|
+
id: _propTypes["default"].string.isRequired,
|
|
262
|
+
label: _propTypes["default"].string,
|
|
263
|
+
timeZone: _propTypes["default"].string.isRequired,
|
|
264
|
+
gmt: _propTypes["default"].string.isRequired,
|
|
265
|
+
numericOffset: _propTypes["default"].number.isRequired,
|
|
266
|
+
searchTags: _propTypes["default"].string.isRequired
|
|
267
|
+
}))
|
|
239
268
|
};
|
|
240
269
|
TimeZonePicker.defaultProps = {
|
|
241
270
|
emptySearchText: 'No Search Result',
|
|
@@ -244,6 +273,7 @@ TimeZonePicker.defaultProps = {
|
|
|
244
273
|
hour12: true,
|
|
245
274
|
hour: '2-digit',
|
|
246
275
|
minute: '2-digit'
|
|
247
|
-
}
|
|
276
|
+
},
|
|
277
|
+
timezoneFormat: 'gmt'
|
|
248
278
|
};
|
|
249
279
|
var _default = exports["default"] = TimeZonePicker;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
5
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] = exports.WithCustomTimeZone = exports.Default = exports.Controlled = void 0;
|
|
8
|
+
exports["default"] = exports.WithCustomTimeZone = exports.UTCFormat = exports.Default = exports.CustomFormat = exports.Controlled = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
@@ -50,4 +50,52 @@ var WithCustomTimeZone = exports.WithCustomTimeZone = function WithCustomTimeZon
|
|
|
50
50
|
additionalTimeZones: customTimeZone,
|
|
51
51
|
label: "With Custom Time Zone (Africa/Juba)"
|
|
52
52
|
}));
|
|
53
|
+
};
|
|
54
|
+
var UTCFormat = exports.UTCFormat = function UTCFormat(args) {
|
|
55
|
+
return (0, _react2.jsx)(_index.TimeZonePicker, (0, _extends2["default"])({}, args, {
|
|
56
|
+
timezoneFormat: "utc",
|
|
57
|
+
label: "UTC Format Example"
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
var CustomFormat = exports.CustomFormat = function CustomFormat(args) {
|
|
61
|
+
/**
|
|
62
|
+
* When timezoneFormat="custom", provide your own items array.
|
|
63
|
+
* Each item must have the following shape:
|
|
64
|
+
* - key: Unique key for the item (e.g., "America/New York UTC-05:00")
|
|
65
|
+
* - id: IANA timezone string (e.g., "America/New_York")
|
|
66
|
+
* - label: Display label (e.g., "Eastern Time")
|
|
67
|
+
* - timeZone: Display timezone name (e.g., "America/New York")
|
|
68
|
+
* - gmt: Offset string to display (e.g., "UTC-05:00" or any custom prefix)
|
|
69
|
+
* - numericOffset: Numeric offset in hours for sorting (e.g., -5)
|
|
70
|
+
* - searchTags: Uppercase string used for filtering (e.g., "UTC-05:00 AMERICA/NEW_YORK EASTERN TIME")
|
|
71
|
+
*/
|
|
72
|
+
var customItems = [{
|
|
73
|
+
key: 'America/New York UTC-05:00',
|
|
74
|
+
id: 'America/New_York',
|
|
75
|
+
label: 'Eastern Time',
|
|
76
|
+
timeZone: 'America/New York',
|
|
77
|
+
gmt: 'UTC-05:00',
|
|
78
|
+
numericOffset: -5,
|
|
79
|
+
searchTags: 'UTC-05:00 AMERICA/NEW_YORK AMERICA/NEW YORK EASTERN TIME'
|
|
80
|
+
}, {
|
|
81
|
+
key: 'America/Chicago UTC-06:00',
|
|
82
|
+
id: 'America/Chicago',
|
|
83
|
+
label: 'Central Time',
|
|
84
|
+
timeZone: 'America/Chicago',
|
|
85
|
+
gmt: 'UTC-06:00',
|
|
86
|
+
numericOffset: -6,
|
|
87
|
+
searchTags: 'UTC-06:00 AMERICA/CHICAGO CENTRAL TIME'
|
|
88
|
+
}, {
|
|
89
|
+
key: 'America/Los Angeles UTC-08:00',
|
|
90
|
+
id: 'America/Los_Angeles',
|
|
91
|
+
label: 'Pacific Time',
|
|
92
|
+
timeZone: 'America/Los Angeles',
|
|
93
|
+
gmt: 'UTC-08:00',
|
|
94
|
+
numericOffset: -8,
|
|
95
|
+
searchTags: 'UTC-08:00 AMERICA/LOS_ANGELES AMERICA/LOS ANGELES PACIFIC TIME'
|
|
96
|
+
}];
|
|
97
|
+
return (0, _react2.jsx)(_index.TimeZonePicker, (0, _extends2["default"])({}, args, {
|
|
98
|
+
items: customItems,
|
|
99
|
+
label: "Custom Format Example"
|
|
100
|
+
}));
|
|
53
101
|
};
|
|
@@ -20,7 +20,7 @@ var _testWrapper = require("../../utils/testUtils/testWrapper");
|
|
|
20
20
|
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
|
21
21
|
var _helper = require("./helper");
|
|
22
22
|
var _react2 = require("@emotion/react");
|
|
23
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof _Symbol ? _Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return _Object$defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = _Object$create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = _Object$getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(l); function g(t) { var
|
|
23
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof _Symbol ? _Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return _Object$defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = _Object$create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = _Object$getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(l); function g(t) { var _context18; _forEachInstanceProperty(_context18 = ["next", "throw", "return"]).call(_context18, function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], _forEachInstanceProperty(t).call(t, w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = _Object$create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = _Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { var _context19; if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, _forEachInstanceProperty(_context19 = this.tryEntries).call(_context19, m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+_sliceInstanceProperty(e).call(e, 1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
|
|
24
24
|
jest.mock('./helper', function () {
|
|
25
25
|
return {
|
|
26
26
|
getGmtAndOffset: jest.fn().mockReturnValue({
|
|
@@ -393,4 +393,157 @@ test('displays pre-selected value with controlled inputValue', function () {
|
|
|
393
393
|
});
|
|
394
394
|
var input = _testWrapper.screen.getByRole('combobox');
|
|
395
395
|
expect(input).toHaveValue(expectedOptionText);
|
|
396
|
-
});
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// timezoneFormat prop tests
|
|
399
|
+
|
|
400
|
+
test('defaults to GMT format when timezoneFormat is not provided', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1() {
|
|
401
|
+
var input;
|
|
402
|
+
return _regeneratorRuntime().wrap(function _callee1$(_context12) {
|
|
403
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
404
|
+
case 0:
|
|
405
|
+
getComponent();
|
|
406
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
407
|
+
_context12.next = 4;
|
|
408
|
+
return _userEvent["default"].type(input, 'America/New York');
|
|
409
|
+
case 4:
|
|
410
|
+
expect(_testWrapper.screen.getByText('GMT-00:00')).toBeInTheDocument();
|
|
411
|
+
case 5:
|
|
412
|
+
case "end":
|
|
413
|
+
return _context12.stop();
|
|
414
|
+
}
|
|
415
|
+
}, _callee1);
|
|
416
|
+
})));
|
|
417
|
+
test('renders items with GMT prefix when timezoneFormat="gmt"', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
418
|
+
var input;
|
|
419
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context13) {
|
|
420
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
421
|
+
case 0:
|
|
422
|
+
getComponent({
|
|
423
|
+
timezoneFormat: 'gmt'
|
|
424
|
+
});
|
|
425
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
426
|
+
_context13.next = 4;
|
|
427
|
+
return _userEvent["default"].type(input, 'America/New York');
|
|
428
|
+
case 4:
|
|
429
|
+
expect(_testWrapper.screen.getByText('GMT-00:00')).toBeInTheDocument();
|
|
430
|
+
case 5:
|
|
431
|
+
case "end":
|
|
432
|
+
return _context13.stop();
|
|
433
|
+
}
|
|
434
|
+
}, _callee10);
|
|
435
|
+
})));
|
|
436
|
+
test('renders items with UTC prefix when timezoneFormat="utc"', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
437
|
+
var input;
|
|
438
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context14) {
|
|
439
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
440
|
+
case 0:
|
|
441
|
+
_helper.getGmtAndOffset.mockReturnValue({
|
|
442
|
+
gmt: 'UTC-00:00',
|
|
443
|
+
numericOffset: 0
|
|
444
|
+
});
|
|
445
|
+
getComponent({
|
|
446
|
+
timezoneFormat: 'utc'
|
|
447
|
+
});
|
|
448
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
449
|
+
_context14.next = 5;
|
|
450
|
+
return _userEvent["default"].type(input, 'America/New York');
|
|
451
|
+
case 5:
|
|
452
|
+
expect(_testWrapper.screen.getByText('UTC-00:00')).toBeInTheDocument();
|
|
453
|
+
case 6:
|
|
454
|
+
case "end":
|
|
455
|
+
return _context14.stop();
|
|
456
|
+
}
|
|
457
|
+
}, _callee11);
|
|
458
|
+
})));
|
|
459
|
+
test('selection callback returns key with UTC prefix when timezoneFormat="utc"', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
460
|
+
var onSelectionChange, timezone, input, expectedKey, option;
|
|
461
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context15) {
|
|
462
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
463
|
+
case 0:
|
|
464
|
+
_helper.getGmtAndOffset.mockReturnValue({
|
|
465
|
+
gmt: 'UTC-00:00',
|
|
466
|
+
numericOffset: 0
|
|
467
|
+
});
|
|
468
|
+
onSelectionChange = jest.fn();
|
|
469
|
+
timezone = 'America/New York';
|
|
470
|
+
getComponent({
|
|
471
|
+
timezoneFormat: 'utc',
|
|
472
|
+
onSelectionChange: onSelectionChange
|
|
473
|
+
});
|
|
474
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
475
|
+
_context15.next = 7;
|
|
476
|
+
return _userEvent["default"].type(input, timezone);
|
|
477
|
+
case 7:
|
|
478
|
+
expectedKey = "".concat(timezone, " UTC-00:00");
|
|
479
|
+
option = _testWrapper.screen.getByRole('option', {
|
|
480
|
+
key: expectedKey
|
|
481
|
+
});
|
|
482
|
+
_context15.next = 11;
|
|
483
|
+
return _userEvent["default"].click(option);
|
|
484
|
+
case 11:
|
|
485
|
+
expect(onSelectionChange).toHaveBeenCalledWith(expectedKey);
|
|
486
|
+
case 12:
|
|
487
|
+
case "end":
|
|
488
|
+
return _context15.stop();
|
|
489
|
+
}
|
|
490
|
+
}, _callee12);
|
|
491
|
+
})));
|
|
492
|
+
test('renders only custom items when items prop is provided', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
493
|
+
var customItems, input;
|
|
494
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context16) {
|
|
495
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
496
|
+
case 0:
|
|
497
|
+
customItems = [{
|
|
498
|
+
key: 'Europe/London CUS+00:00',
|
|
499
|
+
id: 'Europe/London',
|
|
500
|
+
label: 'Custom London',
|
|
501
|
+
timeZone: 'Europe/London',
|
|
502
|
+
gmt: 'CUS+00:00',
|
|
503
|
+
numericOffset: 0,
|
|
504
|
+
searchTags: 'CUS+00:00 EUROPE/LONDON CUSTOM LONDON'
|
|
505
|
+
}];
|
|
506
|
+
getComponent({
|
|
507
|
+
items: customItems
|
|
508
|
+
});
|
|
509
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
510
|
+
_context16.next = 5;
|
|
511
|
+
return _userEvent["default"].type(input, 'London');
|
|
512
|
+
case 5:
|
|
513
|
+
expect(_testWrapper.screen.getByText('Europe/London')).toBeInTheDocument();
|
|
514
|
+
expect(_testWrapper.screen.getByText('CUS+00:00')).toBeInTheDocument();
|
|
515
|
+
case 7:
|
|
516
|
+
case "end":
|
|
517
|
+
return _context16.stop();
|
|
518
|
+
}
|
|
519
|
+
}, _callee13);
|
|
520
|
+
})));
|
|
521
|
+
test('does not render default timezones when items prop is provided', /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
522
|
+
var customItems, input;
|
|
523
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context17) {
|
|
524
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
525
|
+
case 0:
|
|
526
|
+
customItems = [{
|
|
527
|
+
key: 'Europe/London CUS+00:00',
|
|
528
|
+
id: 'Europe/London',
|
|
529
|
+
label: 'Custom London',
|
|
530
|
+
timeZone: 'Europe/London',
|
|
531
|
+
gmt: 'CUS+00:00',
|
|
532
|
+
numericOffset: 0,
|
|
533
|
+
searchTags: 'CUS+00:00 EUROPE/LONDON CUSTOM LONDON'
|
|
534
|
+
}];
|
|
535
|
+
getComponent({
|
|
536
|
+
items: customItems
|
|
537
|
+
});
|
|
538
|
+
input = _testWrapper.screen.getByRole('combobox');
|
|
539
|
+
_context17.next = 5;
|
|
540
|
+
return _userEvent["default"].type(input, 'Pacific/Apia');
|
|
541
|
+
case 5:
|
|
542
|
+
// Should show empty state since default timezones are not loaded
|
|
543
|
+
expect(_testWrapper.screen.getByText('No Search Result')).toBeInTheDocument();
|
|
544
|
+
case 6:
|
|
545
|
+
case "end":
|
|
546
|
+
return _context17.stop();
|
|
547
|
+
}
|
|
548
|
+
}, _callee14);
|
|
549
|
+
})));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const getOffSetString: (timeZone: any) => string;
|
|
1
|
+
export declare const getOffSetString: (timeZone: any, format?: string) => string;
|
|
2
2
|
export declare const getNumericOffset: (offsetString: any) => number;
|
|
3
|
-
export declare const getGmtAndOffset: (timeZone: any) => {
|
|
3
|
+
export declare const getGmtAndOffset: (timeZone: any, format?: string) => {
|
|
4
4
|
gmt: string;
|
|
5
5
|
numericOffset: number;
|
|
6
6
|
};
|
|
@@ -11,6 +11,7 @@ var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stabl
|
|
|
11
11
|
var _parseInt2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/parse-int"));
|
|
12
12
|
var getOffSetString = exports.getOffSetString = function getOffSetString(timeZone) {
|
|
13
13
|
var _parts$find;
|
|
14
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gmt';
|
|
14
15
|
// Use Intl.DateTimeFormat to get the GMT offset string
|
|
15
16
|
var parts = new Intl.DateTimeFormat('en-US', {
|
|
16
17
|
timeZone: timeZone,
|
|
@@ -21,10 +22,13 @@ var getOffSetString = exports.getOffSetString = function getOffSetString(timeZon
|
|
|
21
22
|
var offsetString = ((_parts$find = (0, _find["default"])(parts).call(parts, function (p) {
|
|
22
23
|
return p.type === 'timeZoneName';
|
|
23
24
|
})) === null || _parts$find === void 0 ? void 0 : _parts$find.value) || 'GMT+00:00';
|
|
24
|
-
if (offsetString
|
|
25
|
-
|
|
25
|
+
if (offsetString === 'GMT') {
|
|
26
|
+
offsetString = 'GMT+00:00';
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
if (format === 'utc') {
|
|
29
|
+
return offsetString.replace('GMT', 'UTC');
|
|
30
|
+
}
|
|
31
|
+
return offsetString;
|
|
28
32
|
};
|
|
29
33
|
var getNumericOffset = exports.getNumericOffset = function getNumericOffset(offsetString) {
|
|
30
34
|
// Convert GMT offset string to numeric offset in hours
|
|
@@ -41,18 +45,20 @@ var getNumericOffset = exports.getNumericOffset = function getNumericOffset(offs
|
|
|
41
45
|
return 0;
|
|
42
46
|
};
|
|
43
47
|
var getGmtAndOffset = exports.getGmtAndOffset = function getGmtAndOffset(timeZone) {
|
|
48
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gmt';
|
|
44
49
|
try {
|
|
45
|
-
var offsetString = getOffSetString(timeZone);
|
|
50
|
+
var offsetString = getOffSetString(timeZone, format);
|
|
46
51
|
var numericOffset = getNumericOffset(offsetString);
|
|
47
52
|
|
|
48
|
-
// Return both the
|
|
53
|
+
// Return both the offset string and numeric offset
|
|
49
54
|
return {
|
|
50
55
|
gmt: offsetString,
|
|
51
56
|
numericOffset: numericOffset
|
|
52
57
|
};
|
|
53
58
|
} catch (e) {
|
|
59
|
+
var fallbackPrefix = format === 'utc' ? 'UTC' : 'GMT';
|
|
54
60
|
return {
|
|
55
|
-
gmt:
|
|
61
|
+
gmt: "".concat(fallbackPrefix, "+00:00"),
|
|
56
62
|
numericOffset: 0
|
|
57
63
|
};
|
|
58
64
|
}
|
|
@@ -21,6 +21,14 @@ describe('TimeZonePicker helpers', function () {
|
|
|
21
21
|
var result = (0, _helper.getOffSetString)('UTC');
|
|
22
22
|
expect(result).toBe('GMT+00:00');
|
|
23
23
|
});
|
|
24
|
+
test('returns UTC offset string when format is utc', function () {
|
|
25
|
+
var result = (0, _helper.getOffSetString)('America/New_York', 'utc');
|
|
26
|
+
expect(result).toMatch(/UTC[+-]\d{2}:\d{2}/);
|
|
27
|
+
});
|
|
28
|
+
test('returns UTC+00:00 for UTC timezone with utc format', function () {
|
|
29
|
+
var result = (0, _helper.getOffSetString)('UTC', 'utc');
|
|
30
|
+
expect(result).toBe('UTC+00:00');
|
|
31
|
+
});
|
|
24
32
|
});
|
|
25
33
|
describe('getNumericOffset', function () {
|
|
26
34
|
test('parses positive offset correctly', function () {
|
|
@@ -75,5 +83,24 @@ describe('TimeZonePicker helpers', function () {
|
|
|
75
83
|
expect(result.gmt).toMatch(/GMT\+05:30/);
|
|
76
84
|
expect(result.numericOffset).toBe(5.5);
|
|
77
85
|
});
|
|
86
|
+
test('returns UTC string when format is utc', function () {
|
|
87
|
+
var result = (0, _helper.getGmtAndOffset)('America/New_York', 'utc');
|
|
88
|
+
expect(result.gmt).toMatch(/UTC[+-]\d{2}:\d{2}/);
|
|
89
|
+
expect((0, _typeof2["default"])(result.numericOffset)).toBe('number');
|
|
90
|
+
});
|
|
91
|
+
test('returns UTC+00:00 for UTC timezone with utc format', function () {
|
|
92
|
+
var result = (0, _helper.getGmtAndOffset)('UTC', 'utc');
|
|
93
|
+
expect(result).toEqual({
|
|
94
|
+
gmt: 'UTC+00:00',
|
|
95
|
+
numericOffset: 0
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
test('returns UTC+00:00 and 0 for invalid timezone with utc format', function () {
|
|
99
|
+
var result = (0, _helper.getGmtAndOffset)('Invalid/Timezone', 'utc');
|
|
100
|
+
expect(result).toEqual({
|
|
101
|
+
gmt: 'UTC+00:00',
|
|
102
|
+
numericOffset: 0
|
|
103
|
+
});
|
|
104
|
+
});
|
|
78
105
|
});
|
|
79
106
|
});
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
3
3
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["additionalTimeZones", "emptySearchText", "locales", "localeOptions", "selectedKey", "onSelectionChange", "inputValue", "onInputChange"];
|
|
5
|
+
var _excluded = ["additionalTimeZones", "emptySearchText", "items", "locales", "localeOptions", "timezoneFormat", "selectedKey", "onSelectionChange", "inputValue", "onInputChange"];
|
|
6
6
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context8, _context9; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context8 = ownKeys(Object(t), !0)).call(_context8, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context9 = ownKeys(Object(t))).call(_context9, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
8
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
@@ -44,8 +44,10 @@ var createSearchTags = function createSearchTags(_ref) {
|
|
|
44
44
|
var TimeZonePicker = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
45
45
|
var additionalTimeZones = props.additionalTimeZones,
|
|
46
46
|
emptySearchText = props.emptySearchText,
|
|
47
|
+
itemsProp = props.items,
|
|
47
48
|
locales = props.locales,
|
|
48
49
|
localeOptions = props.localeOptions,
|
|
50
|
+
timezoneFormat = props.timezoneFormat,
|
|
49
51
|
selectedKeyProp = props.selectedKey,
|
|
50
52
|
onSelectionChangeProp = props.onSelectionChange,
|
|
51
53
|
inputValueProp = props.inputValue,
|
|
@@ -70,13 +72,16 @@ var TimeZonePicker = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
70
72
|
});
|
|
71
73
|
var allTimeZones = useMemo(function () {
|
|
72
74
|
var _context4, _context5;
|
|
75
|
+
if (itemsProp) {
|
|
76
|
+
return itemsProp;
|
|
77
|
+
}
|
|
73
78
|
var sourceList = additionalTimeZones ? _objectSpread(_objectSpread({}, defaultTimezones), additionalTimeZones) : defaultTimezones;
|
|
74
79
|
return _sortInstanceProperty(_context4 = _mapInstanceProperty(_context5 = _Object$entries(sourceList)).call(_context5, function (_ref2) {
|
|
75
80
|
var _context6;
|
|
76
81
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
77
82
|
label = _ref3[0],
|
|
78
83
|
tzValue = _ref3[1];
|
|
79
|
-
var _getGmtAndOffset = getGmtAndOffset(tzValue),
|
|
84
|
+
var _getGmtAndOffset = getGmtAndOffset(tzValue, timezoneFormat),
|
|
80
85
|
gmt = _getGmtAndOffset.gmt,
|
|
81
86
|
numericOffset = _getGmtAndOffset.numericOffset;
|
|
82
87
|
var displayTz = tzValue.replace(/_/g, ' ');
|
|
@@ -95,7 +100,7 @@ var TimeZonePicker = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
95
100
|
})).call(_context4, function (a, b) {
|
|
96
101
|
return a.numericOffset - b.numericOffset;
|
|
97
102
|
});
|
|
98
|
-
}, [additionalTimeZones]);
|
|
103
|
+
}, [additionalTimeZones, timezoneFormat, itemsProp]);
|
|
99
104
|
|
|
100
105
|
// Sync internal input value when controlled selectedKey changes externally
|
|
101
106
|
useEffect(function () {
|
|
@@ -130,9 +135,13 @@ var TimeZonePicker = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
130
135
|
var now = new Date();
|
|
131
136
|
var map = new _Map();
|
|
132
137
|
_forEachInstanceProperty(allTimeZones).call(allTimeZones, function (tz) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
try {
|
|
139
|
+
map.set(tz.id, now.toLocaleTimeString(locales, _objectSpread({
|
|
140
|
+
timeZone: tz.id
|
|
141
|
+
}, localeOptions)));
|
|
142
|
+
} catch (e) {
|
|
143
|
+
map.set(tz.id, '');
|
|
144
|
+
}
|
|
136
145
|
});
|
|
137
146
|
return map;
|
|
138
147
|
}, [allTimeZones, locales, localeOptions]);
|
|
@@ -223,7 +232,27 @@ TimeZonePicker.propTypes = {
|
|
|
223
232
|
/** The current input value (controlled). */
|
|
224
233
|
inputValue: PropTypes.string,
|
|
225
234
|
/** Handler called when the input value changes. */
|
|
226
|
-
onInputChange: PropTypes.func
|
|
235
|
+
onInputChange: PropTypes.func,
|
|
236
|
+
/**
|
|
237
|
+
* The format to use for timezone offset display.
|
|
238
|
+
* - `'gmt'` (default): Display offsets as GMT (e.g., GMT-08:00)
|
|
239
|
+
* - `'utc'`: Display offsets as UTC (e.g., UTC-08:00)
|
|
240
|
+
*/
|
|
241
|
+
timezoneFormat: PropTypes.oneOf(['gmt', 'utc']),
|
|
242
|
+
/**
|
|
243
|
+
* Custom items to render instead of the default timezone list. When provided, the component
|
|
244
|
+
* uses these items directly. Each item should have the shape:
|
|
245
|
+
* `{ key: string, id: string, label: string, timeZone: string, gmt: string, numericOffset: number, searchTags: string }`
|
|
246
|
+
*/
|
|
247
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
248
|
+
key: PropTypes.string.isRequired,
|
|
249
|
+
id: PropTypes.string.isRequired,
|
|
250
|
+
label: PropTypes.string,
|
|
251
|
+
timeZone: PropTypes.string.isRequired,
|
|
252
|
+
gmt: PropTypes.string.isRequired,
|
|
253
|
+
numericOffset: PropTypes.number.isRequired,
|
|
254
|
+
searchTags: PropTypes.string.isRequired
|
|
255
|
+
}))
|
|
227
256
|
};
|
|
228
257
|
TimeZonePicker.defaultProps = {
|
|
229
258
|
emptySearchText: 'No Search Result',
|
|
@@ -232,6 +261,7 @@ TimeZonePicker.defaultProps = {
|
|
|
232
261
|
hour12: true,
|
|
233
262
|
hour: '2-digit',
|
|
234
263
|
minute: '2-digit'
|
|
235
|
-
}
|
|
264
|
+
},
|
|
265
|
+
timezoneFormat: 'gmt'
|
|
236
266
|
};
|
|
237
267
|
export default TimeZonePicker;
|
|
@@ -42,4 +42,52 @@ export var WithCustomTimeZone = function WithCustomTimeZone(args) {
|
|
|
42
42
|
additionalTimeZones: customTimeZone,
|
|
43
43
|
label: "With Custom Time Zone (Africa/Juba)"
|
|
44
44
|
}));
|
|
45
|
+
};
|
|
46
|
+
export var UTCFormat = function UTCFormat(args) {
|
|
47
|
+
return ___EmotionJSX(TimeZonePicker, _extends({}, args, {
|
|
48
|
+
timezoneFormat: "utc",
|
|
49
|
+
label: "UTC Format Example"
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
export var CustomFormat = function CustomFormat(args) {
|
|
53
|
+
/**
|
|
54
|
+
* When timezoneFormat="custom", provide your own items array.
|
|
55
|
+
* Each item must have the following shape:
|
|
56
|
+
* - key: Unique key for the item (e.g., "America/New York UTC-05:00")
|
|
57
|
+
* - id: IANA timezone string (e.g., "America/New_York")
|
|
58
|
+
* - label: Display label (e.g., "Eastern Time")
|
|
59
|
+
* - timeZone: Display timezone name (e.g., "America/New York")
|
|
60
|
+
* - gmt: Offset string to display (e.g., "UTC-05:00" or any custom prefix)
|
|
61
|
+
* - numericOffset: Numeric offset in hours for sorting (e.g., -5)
|
|
62
|
+
* - searchTags: Uppercase string used for filtering (e.g., "UTC-05:00 AMERICA/NEW_YORK EASTERN TIME")
|
|
63
|
+
*/
|
|
64
|
+
var customItems = [{
|
|
65
|
+
key: 'America/New York UTC-05:00',
|
|
66
|
+
id: 'America/New_York',
|
|
67
|
+
label: 'Eastern Time',
|
|
68
|
+
timeZone: 'America/New York',
|
|
69
|
+
gmt: 'UTC-05:00',
|
|
70
|
+
numericOffset: -5,
|
|
71
|
+
searchTags: 'UTC-05:00 AMERICA/NEW_YORK AMERICA/NEW YORK EASTERN TIME'
|
|
72
|
+
}, {
|
|
73
|
+
key: 'America/Chicago UTC-06:00',
|
|
74
|
+
id: 'America/Chicago',
|
|
75
|
+
label: 'Central Time',
|
|
76
|
+
timeZone: 'America/Chicago',
|
|
77
|
+
gmt: 'UTC-06:00',
|
|
78
|
+
numericOffset: -6,
|
|
79
|
+
searchTags: 'UTC-06:00 AMERICA/CHICAGO CENTRAL TIME'
|
|
80
|
+
}, {
|
|
81
|
+
key: 'America/Los Angeles UTC-08:00',
|
|
82
|
+
id: 'America/Los_Angeles',
|
|
83
|
+
label: 'Pacific Time',
|
|
84
|
+
timeZone: 'America/Los Angeles',
|
|
85
|
+
gmt: 'UTC-08:00',
|
|
86
|
+
numericOffset: -8,
|
|
87
|
+
searchTags: 'UTC-08:00 AMERICA/LOS_ANGELES AMERICA/LOS ANGELES PACIFIC TIME'
|
|
88
|
+
}];
|
|
89
|
+
return ___EmotionJSX(TimeZonePicker, _extends({}, args, {
|
|
90
|
+
items: customItems,
|
|
91
|
+
label: "Custom Format Example"
|
|
92
|
+
}));
|
|
45
93
|
};
|
|
@@ -10,7 +10,7 @@ import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
|
|
10
10
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
|
11
11
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
12
12
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
13
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof _Symbol ? _Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return _Object$defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = _Object$create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = _Object$getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(l); function g(t) { var
|
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return r; }; var t, r = {}, e = Object.prototype, n = e.hasOwnProperty, o = "function" == typeof _Symbol ? _Symbol : {}, i = o.iterator || "@@iterator", a = o.asyncIterator || "@@asyncIterator", u = o.toStringTag || "@@toStringTag"; function c(t, r, e, n) { return _Object$defineProperty(t, r, { value: e, enumerable: !n, configurable: !n, writable: !n }); } try { c({}, ""); } catch (t) { c = function c(t, r, e) { return t[r] = e; }; } function h(r, e, n, o) { var i = e && e.prototype instanceof Generator ? e : Generator, a = _Object$create(i.prototype); return c(a, "_invoke", function (r, e, n) { var o = 1; return function (i, a) { if (3 === o) throw Error("Generator is already running"); if (4 === o) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var u = n.delegate; if (u) { var c = d(u, n); if (c) { if (c === f) continue; return c; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (1 === o) throw o = 4, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = 3; var h = s(r, e, n); if ("normal" === h.type) { if (o = n.done ? 4 : 2, h.arg === f) continue; return { value: h.arg, done: n.done }; } "throw" === h.type && (o = 4, n.method = "throw", n.arg = h.arg); } }; }(r, n, new Context(o || [])), !0), a; } function s(t, r, e) { try { return { type: "normal", arg: t.call(r, e) }; } catch (t) { return { type: "throw", arg: t }; } } r.wrap = h; var f = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var l = {}; c(l, i, function () { return this; }); var p = _Object$getPrototypeOf, y = p && p(p(x([]))); y && y !== e && n.call(y, i) && (l = y); var v = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(l); function g(t) { var _context18; _forEachInstanceProperty(_context18 = ["next", "throw", "return"]).call(_context18, function (r) { c(t, r, function (t) { return this._invoke(r, t); }); }); } function AsyncIterator(t, r) { function e(o, i, a, u) { var c = s(t[o], t, i); if ("throw" !== c.type) { var h = c.arg, f = h.value; return f && "object" == _typeof(f) && n.call(f, "__await") ? r.resolve(f.__await).then(function (t) { e("next", t, a, u); }, function (t) { e("throw", t, a, u); }) : r.resolve(f).then(function (t) { h.value = t, a(h); }, function (t) { return e("throw", t, a, u); }); } u(c.arg); } var o; c(this, "_invoke", function (t, n) { function i() { return new r(function (r, o) { e(t, n, r, o); }); } return o = o ? o.then(i, i) : i(); }, !0); } function d(r, e) { var n = e.method, o = r.i[n]; if (o === t) return e.delegate = null, "throw" === n && r.i["return"] && (e.method = "return", e.arg = t, d(r, e), "throw" === e.method) || "return" !== n && (e.method = "throw", e.arg = new TypeError("The iterator does not provide a '" + n + "' method")), f; var i = s(o, r.i, e.arg); if ("throw" === i.type) return e.method = "throw", e.arg = i.arg, e.delegate = null, f; var a = i.arg; return a ? a.done ? (e[r.r] = a.value, e.next = r.n, "return" !== e.method && (e.method = "next", e.arg = t), e.delegate = null, f) : a : (e.method = "throw", e.arg = new TypeError("iterator result is not an object"), e.delegate = null, f); } function w(t) { this.tryEntries.push(t); } function m(r) { var e = r[4] || {}; e.type = "normal", e.arg = t, r[4] = e; } function Context(t) { this.tryEntries = [[-1]], _forEachInstanceProperty(t).call(t, w, this), this.reset(!0); } function x(r) { if (null != r) { var e = r[i]; if (e) return e.call(r); if ("function" == typeof r.next) return r; if (!isNaN(r.length)) { var o = -1, a = function e() { for (; ++o < r.length;) if (n.call(r, o)) return e.value = r[o], e.done = !1, e; return e.value = t, e.done = !0, e; }; return a.next = a; } } throw new TypeError(_typeof(r) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, c(v, "constructor", GeneratorFunctionPrototype), c(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = c(GeneratorFunctionPrototype, u, "GeneratorFunction"), r.isGeneratorFunction = function (t) { var r = "function" == typeof t && t.constructor; return !!r && (r === GeneratorFunction || "GeneratorFunction" === (r.displayName || r.name)); }, r.mark = function (t) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, c(t, u, "GeneratorFunction")), t.prototype = _Object$create(v), t; }, r.awrap = function (t) { return { __await: t }; }, g(AsyncIterator.prototype), c(AsyncIterator.prototype, a, function () { return this; }), r.AsyncIterator = AsyncIterator, r.async = function (t, e, n, o, i) { void 0 === i && (i = _Promise); var a = new AsyncIterator(h(t, e, n, o), i); return r.isGeneratorFunction(e) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, g(v), c(v, u, "Generator"), c(v, i, function () { return this; }), c(v, "toString", function () { return "[object Generator]"; }), r.keys = function (t) { var r = Object(t), e = []; for (var n in r) e.unshift(n); return function t() { for (; e.length;) if ((n = e.pop()) in r) return t.value = n, t.done = !1, t; return t.done = !0, t; }; }, r.values = x, Context.prototype = { constructor: Context, reset: function reset(r) { var _context19; if (this.prev = this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, _forEachInstanceProperty(_context19 = this.tryEntries).call(_context19, m), !r) for (var e in this) "t" === e.charAt(0) && n.call(this, e) && !isNaN(+_sliceInstanceProperty(e).call(e, 1)) && (this[e] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0][4]; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(r) { if (this.done) throw r; var e = this; function n(t) { a.type = "throw", a.arg = r, e.next = t; } for (var o = e.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i[4], u = this.prev, c = i[1], h = i[2]; if (-1 === i[0]) return n("end"), !1; if (!c && !h) throw Error("try statement without catch or finally"); if (null != i[0] && i[0] <= u) { if (u < c) return this.method = "next", this.arg = t, n(c), !0; if (u < h) return n(h), !1; } } }, abrupt: function abrupt(t, r) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var n = this.tryEntries[e]; if (n[0] > -1 && n[0] <= this.prev && this.prev < n[2]) { var o = n; break; } } o && ("break" === t || "continue" === t) && o[0] <= r && r <= o[2] && (o = null); var i = o ? o[4] : {}; return i.type = t, i.arg = r, o ? (this.method = "next", this.next = o[2], f) : this.complete(i); }, complete: function complete(t, r) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && r && (this.next = r), f; }, finish: function finish(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[2] === t) return this.complete(e[4], e[3]), m(e), f; } }, "catch": function _catch(t) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var e = this.tryEntries[r]; if (e[0] === t) { var n = e[4]; if ("throw" === n.type) { var o = n.arg; m(e); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(r, e, n) { return this.delegate = { i: x(r), r: e, n: n }, "next" === this.method && (this.arg = t), f; } }, r; }
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import userEvent from '@testing-library/user-event';
|
|
16
16
|
import { OverlayProvider, TimeZonePicker } from '../../index';
|
|
@@ -390,4 +390,157 @@ test('displays pre-selected value with controlled inputValue', function () {
|
|
|
390
390
|
});
|
|
391
391
|
var input = screen.getByRole('combobox');
|
|
392
392
|
expect(input).toHaveValue(expectedOptionText);
|
|
393
|
-
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// timezoneFormat prop tests
|
|
396
|
+
|
|
397
|
+
test('defaults to GMT format when timezoneFormat is not provided', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee1() {
|
|
398
|
+
var input;
|
|
399
|
+
return _regeneratorRuntime().wrap(function _callee1$(_context12) {
|
|
400
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
401
|
+
case 0:
|
|
402
|
+
getComponent();
|
|
403
|
+
input = screen.getByRole('combobox');
|
|
404
|
+
_context12.next = 4;
|
|
405
|
+
return userEvent.type(input, 'America/New York');
|
|
406
|
+
case 4:
|
|
407
|
+
expect(screen.getByText('GMT-00:00')).toBeInTheDocument();
|
|
408
|
+
case 5:
|
|
409
|
+
case "end":
|
|
410
|
+
return _context12.stop();
|
|
411
|
+
}
|
|
412
|
+
}, _callee1);
|
|
413
|
+
})));
|
|
414
|
+
test('renders items with GMT prefix when timezoneFormat="gmt"', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
415
|
+
var input;
|
|
416
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context13) {
|
|
417
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
418
|
+
case 0:
|
|
419
|
+
getComponent({
|
|
420
|
+
timezoneFormat: 'gmt'
|
|
421
|
+
});
|
|
422
|
+
input = screen.getByRole('combobox');
|
|
423
|
+
_context13.next = 4;
|
|
424
|
+
return userEvent.type(input, 'America/New York');
|
|
425
|
+
case 4:
|
|
426
|
+
expect(screen.getByText('GMT-00:00')).toBeInTheDocument();
|
|
427
|
+
case 5:
|
|
428
|
+
case "end":
|
|
429
|
+
return _context13.stop();
|
|
430
|
+
}
|
|
431
|
+
}, _callee10);
|
|
432
|
+
})));
|
|
433
|
+
test('renders items with UTC prefix when timezoneFormat="utc"', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
434
|
+
var input;
|
|
435
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context14) {
|
|
436
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
437
|
+
case 0:
|
|
438
|
+
getGmtAndOffset.mockReturnValue({
|
|
439
|
+
gmt: 'UTC-00:00',
|
|
440
|
+
numericOffset: 0
|
|
441
|
+
});
|
|
442
|
+
getComponent({
|
|
443
|
+
timezoneFormat: 'utc'
|
|
444
|
+
});
|
|
445
|
+
input = screen.getByRole('combobox');
|
|
446
|
+
_context14.next = 5;
|
|
447
|
+
return userEvent.type(input, 'America/New York');
|
|
448
|
+
case 5:
|
|
449
|
+
expect(screen.getByText('UTC-00:00')).toBeInTheDocument();
|
|
450
|
+
case 6:
|
|
451
|
+
case "end":
|
|
452
|
+
return _context14.stop();
|
|
453
|
+
}
|
|
454
|
+
}, _callee11);
|
|
455
|
+
})));
|
|
456
|
+
test('selection callback returns key with UTC prefix when timezoneFormat="utc"', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
457
|
+
var onSelectionChange, timezone, input, expectedKey, option;
|
|
458
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context15) {
|
|
459
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
460
|
+
case 0:
|
|
461
|
+
getGmtAndOffset.mockReturnValue({
|
|
462
|
+
gmt: 'UTC-00:00',
|
|
463
|
+
numericOffset: 0
|
|
464
|
+
});
|
|
465
|
+
onSelectionChange = jest.fn();
|
|
466
|
+
timezone = 'America/New York';
|
|
467
|
+
getComponent({
|
|
468
|
+
timezoneFormat: 'utc',
|
|
469
|
+
onSelectionChange: onSelectionChange
|
|
470
|
+
});
|
|
471
|
+
input = screen.getByRole('combobox');
|
|
472
|
+
_context15.next = 7;
|
|
473
|
+
return userEvent.type(input, timezone);
|
|
474
|
+
case 7:
|
|
475
|
+
expectedKey = "".concat(timezone, " UTC-00:00");
|
|
476
|
+
option = screen.getByRole('option', {
|
|
477
|
+
key: expectedKey
|
|
478
|
+
});
|
|
479
|
+
_context15.next = 11;
|
|
480
|
+
return userEvent.click(option);
|
|
481
|
+
case 11:
|
|
482
|
+
expect(onSelectionChange).toHaveBeenCalledWith(expectedKey);
|
|
483
|
+
case 12:
|
|
484
|
+
case "end":
|
|
485
|
+
return _context15.stop();
|
|
486
|
+
}
|
|
487
|
+
}, _callee12);
|
|
488
|
+
})));
|
|
489
|
+
test('renders only custom items when items prop is provided', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
490
|
+
var customItems, input;
|
|
491
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context16) {
|
|
492
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
493
|
+
case 0:
|
|
494
|
+
customItems = [{
|
|
495
|
+
key: 'Europe/London CUS+00:00',
|
|
496
|
+
id: 'Europe/London',
|
|
497
|
+
label: 'Custom London',
|
|
498
|
+
timeZone: 'Europe/London',
|
|
499
|
+
gmt: 'CUS+00:00',
|
|
500
|
+
numericOffset: 0,
|
|
501
|
+
searchTags: 'CUS+00:00 EUROPE/LONDON CUSTOM LONDON'
|
|
502
|
+
}];
|
|
503
|
+
getComponent({
|
|
504
|
+
items: customItems
|
|
505
|
+
});
|
|
506
|
+
input = screen.getByRole('combobox');
|
|
507
|
+
_context16.next = 5;
|
|
508
|
+
return userEvent.type(input, 'London');
|
|
509
|
+
case 5:
|
|
510
|
+
expect(screen.getByText('Europe/London')).toBeInTheDocument();
|
|
511
|
+
expect(screen.getByText('CUS+00:00')).toBeInTheDocument();
|
|
512
|
+
case 7:
|
|
513
|
+
case "end":
|
|
514
|
+
return _context16.stop();
|
|
515
|
+
}
|
|
516
|
+
}, _callee13);
|
|
517
|
+
})));
|
|
518
|
+
test('does not render default timezones when items prop is provided', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
519
|
+
var customItems, input;
|
|
520
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context17) {
|
|
521
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
522
|
+
case 0:
|
|
523
|
+
customItems = [{
|
|
524
|
+
key: 'Europe/London CUS+00:00',
|
|
525
|
+
id: 'Europe/London',
|
|
526
|
+
label: 'Custom London',
|
|
527
|
+
timeZone: 'Europe/London',
|
|
528
|
+
gmt: 'CUS+00:00',
|
|
529
|
+
numericOffset: 0,
|
|
530
|
+
searchTags: 'CUS+00:00 EUROPE/LONDON CUSTOM LONDON'
|
|
531
|
+
}];
|
|
532
|
+
getComponent({
|
|
533
|
+
items: customItems
|
|
534
|
+
});
|
|
535
|
+
input = screen.getByRole('combobox');
|
|
536
|
+
_context17.next = 5;
|
|
537
|
+
return userEvent.type(input, 'Pacific/Apia');
|
|
538
|
+
case 5:
|
|
539
|
+
// Should show empty state since default timezones are not loaded
|
|
540
|
+
expect(screen.getByText('No Search Result')).toBeInTheDocument();
|
|
541
|
+
case 6:
|
|
542
|
+
case "end":
|
|
543
|
+
return _context17.stop();
|
|
544
|
+
}
|
|
545
|
+
}, _callee14);
|
|
546
|
+
})));
|
|
@@ -3,6 +3,7 @@ import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instanc
|
|
|
3
3
|
import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
|
|
4
4
|
export var getOffSetString = function getOffSetString(timeZone) {
|
|
5
5
|
var _parts$find;
|
|
6
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gmt';
|
|
6
7
|
// Use Intl.DateTimeFormat to get the GMT offset string
|
|
7
8
|
var parts = new Intl.DateTimeFormat('en-US', {
|
|
8
9
|
timeZone: timeZone,
|
|
@@ -13,10 +14,13 @@ export var getOffSetString = function getOffSetString(timeZone) {
|
|
|
13
14
|
var offsetString = ((_parts$find = _findInstanceProperty(parts).call(parts, function (p) {
|
|
14
15
|
return p.type === 'timeZoneName';
|
|
15
16
|
})) === null || _parts$find === void 0 ? void 0 : _parts$find.value) || 'GMT+00:00';
|
|
16
|
-
if (offsetString
|
|
17
|
-
|
|
17
|
+
if (offsetString === 'GMT') {
|
|
18
|
+
offsetString = 'GMT+00:00';
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
if (format === 'utc') {
|
|
21
|
+
return offsetString.replace('GMT', 'UTC');
|
|
22
|
+
}
|
|
23
|
+
return offsetString;
|
|
20
24
|
};
|
|
21
25
|
export var getNumericOffset = function getNumericOffset(offsetString) {
|
|
22
26
|
// Convert GMT offset string to numeric offset in hours
|
|
@@ -33,18 +37,20 @@ export var getNumericOffset = function getNumericOffset(offsetString) {
|
|
|
33
37
|
return 0;
|
|
34
38
|
};
|
|
35
39
|
export var getGmtAndOffset = function getGmtAndOffset(timeZone) {
|
|
40
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gmt';
|
|
36
41
|
try {
|
|
37
|
-
var offsetString = getOffSetString(timeZone);
|
|
42
|
+
var offsetString = getOffSetString(timeZone, format);
|
|
38
43
|
var numericOffset = getNumericOffset(offsetString);
|
|
39
44
|
|
|
40
|
-
// Return both the
|
|
45
|
+
// Return both the offset string and numeric offset
|
|
41
46
|
return {
|
|
42
47
|
gmt: offsetString,
|
|
43
48
|
numericOffset: numericOffset
|
|
44
49
|
};
|
|
45
50
|
} catch (e) {
|
|
51
|
+
var fallbackPrefix = format === 'utc' ? 'UTC' : 'GMT';
|
|
46
52
|
return {
|
|
47
|
-
gmt:
|
|
53
|
+
gmt: "".concat(fallbackPrefix, "+00:00"),
|
|
48
54
|
numericOffset: 0
|
|
49
55
|
};
|
|
50
56
|
}
|
|
@@ -18,6 +18,14 @@ describe('TimeZonePicker helpers', function () {
|
|
|
18
18
|
var result = getOffSetString('UTC');
|
|
19
19
|
expect(result).toBe('GMT+00:00');
|
|
20
20
|
});
|
|
21
|
+
test('returns UTC offset string when format is utc', function () {
|
|
22
|
+
var result = getOffSetString('America/New_York', 'utc');
|
|
23
|
+
expect(result).toMatch(/UTC[+-]\d{2}:\d{2}/);
|
|
24
|
+
});
|
|
25
|
+
test('returns UTC+00:00 for UTC timezone with utc format', function () {
|
|
26
|
+
var result = getOffSetString('UTC', 'utc');
|
|
27
|
+
expect(result).toBe('UTC+00:00');
|
|
28
|
+
});
|
|
21
29
|
});
|
|
22
30
|
describe('getNumericOffset', function () {
|
|
23
31
|
test('parses positive offset correctly', function () {
|
|
@@ -72,5 +80,24 @@ describe('TimeZonePicker helpers', function () {
|
|
|
72
80
|
expect(result.gmt).toMatch(/GMT\+05:30/);
|
|
73
81
|
expect(result.numericOffset).toBe(5.5);
|
|
74
82
|
});
|
|
83
|
+
test('returns UTC string when format is utc', function () {
|
|
84
|
+
var result = getGmtAndOffset('America/New_York', 'utc');
|
|
85
|
+
expect(result.gmt).toMatch(/UTC[+-]\d{2}:\d{2}/);
|
|
86
|
+
expect(_typeof(result.numericOffset)).toBe('number');
|
|
87
|
+
});
|
|
88
|
+
test('returns UTC+00:00 for UTC timezone with utc format', function () {
|
|
89
|
+
var result = getGmtAndOffset('UTC', 'utc');
|
|
90
|
+
expect(result).toEqual({
|
|
91
|
+
gmt: 'UTC+00:00',
|
|
92
|
+
numericOffset: 0
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
test('returns UTC+00:00 and 0 for invalid timezone with utc format', function () {
|
|
96
|
+
var result = getGmtAndOffset('Invalid/Timezone', 'utc');
|
|
97
|
+
expect(result).toEqual({
|
|
98
|
+
gmt: 'UTC+00:00',
|
|
99
|
+
numericOffset: 0
|
|
100
|
+
});
|
|
101
|
+
});
|
|
75
102
|
});
|
|
76
103
|
});
|