orc-shared 1.3.0-dev.8 → 1.3.0-dev.9

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.
@@ -17,6 +17,12 @@ var _TimePicker = _interopRequireDefault(require("./TimePicker"));
17
17
 
18
18
  var _styles = require("@material-ui/core/styles");
19
19
 
20
+ var _timezoneHelper = require("../../../utils/timezoneHelper");
21
+
22
+ var _metadata = require("../../../selectors/metadata");
23
+
24
+ var _reactRedux = require("react-redux");
25
+
20
26
  var _excluded = ["value", "useTime", "useDate", "onChange", "dateFormat", "showTimeZone", "timeInputLabel", "readOnly", "showTimeSelectOnly", "metadata", "timePickerTimeZone", "error"];
21
27
 
22
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -185,12 +191,14 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
185
191
  var classes = useStyles({
186
192
  readOnly: readOnly
187
193
  });
188
- var startDate = value ? new Date(value) : null;
194
+ var timeZoneName = (0, _timezoneHelper.getTimeZoneByName)(timePickerTimeZone);
195
+ var startDate = value ? timePickerTimeZone ? (0, _timezoneHelper.convertTimeToLocalTimeZone)(new Date(value), timeZoneName) : new Date(value) : null;
189
196
  var disabledCls = (0, _classnames.default)(_defineProperty({}, classes.disabled, props.disabled));
197
+ var localizedTimeZoneName = (0, _reactRedux.useSelector)((0, _metadata.namedLookupLocalizedSelector)("customer", "TimeZone", timePickerTimeZone));
190
198
 
191
199
  var updateDate = function updateDate(date, metadata) {
192
200
  if (onChange) {
193
- onChange(date, metadata);
201
+ onChange(useTime && timePickerTimeZone ? (0, _timezoneHelper.convertTimeToOtherTimeZone)(date, timeZoneName) : date, metadata);
194
202
  }
195
203
  };
196
204
 
@@ -210,7 +218,7 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
210
218
  useTime: useTime != null ? useTime : false,
211
219
  customTimeInput: useTime ? /*#__PURE__*/_react.default.createElement(_TimePicker.default, {
212
220
  showTimeZone: showTimeZone,
213
- requestedTimeZone: timePickerTimeZone
221
+ requestedTimeZone: localizedTimeZoneName
214
222
  }) : null,
215
223
  timeInputLabel: timeInputLabel != null ? timeInputLabel : "",
216
224
  readOnly: readOnly,
@@ -225,12 +233,12 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
225
233
  }, error));
226
234
  };
227
235
 
228
- __signature__(WrappedDatePicker, "useStyles{classes}", function () {
229
- return [useStyles];
236
+ __signature__(WrappedDatePicker, "useStyles{classes}\nuseSelector{localizedTimeZoneName}", function () {
237
+ return [useStyles, _reactRedux.useSelector];
230
238
  });
231
239
 
232
- __signature__(WrappedDatePicker, "useStyles{classes}", function () {
233
- return [useStyles];
240
+ __signature__(WrappedDatePicker, "useStyles{classes}\nuseSelector{localizedTimeZoneName}", function () {
241
+ return [useStyles, _reactRedux.useSelector];
234
242
  });
235
243
 
236
244
  var _default = WrappedDatePicker;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.timeZonesList = exports.getTimeZoneName = exports.getTimeZoneByName = exports.getTimeZone = void 0;
4
+ exports.timeZonesList = exports.getTimeZoneName = exports.getTimeZoneByName = exports.getTimeZone = exports.convertTimeToOtherTimeZone = exports.convertTimeToLocalTimeZone = void 0;
5
+
6
+ var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
7
+
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
9
 
6
10
  (function () {
7
11
  var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
@@ -61,9 +65,32 @@ var getTimeZoneName = function getTimeZoneName() {
61
65
  var customerTimezone = getTimeZone();
62
66
  var timezoneName = timeZonesList.get(customerTimezone);
63
67
  return timezoneName;
64
- };
68
+ }; //converting time from other timezone to local
69
+
65
70
 
66
71
  exports.getTimeZoneName = getTimeZoneName;
72
+
73
+ var convertTimeToLocalTimeZone = function convertTimeToLocalTimeZone(date, timezone) {
74
+ var dateWithoutZone = _momentTimezone.default.tz(date, timezone).format("YYYY-MM-DDTHH:mm:ss.SSS");
75
+
76
+ var localZone = (0, _momentTimezone.default)(dateWithoutZone).format("Z");
77
+ var dateWithLocalZone = [dateWithoutZone, localZone].join("");
78
+ return new Date(dateWithLocalZone);
79
+ }; //converting time from local timezone to other
80
+
81
+
82
+ exports.convertTimeToLocalTimeZone = convertTimeToLocalTimeZone;
83
+
84
+ var convertTimeToOtherTimeZone = function convertTimeToOtherTimeZone(date, timezone) {
85
+ var dateWithoutZone = (0, _momentTimezone.default)(date).format("YYYY-MM-DDTHH:mm:ss.SSS");
86
+
87
+ var otherZone = _momentTimezone.default.tz(date, timezone).format("Z");
88
+
89
+ var dateWithOtherZone = [dateWithoutZone, otherZone].join("");
90
+ return new Date(dateWithOtherZone);
91
+ };
92
+
93
+ exports.convertTimeToOtherTimeZone = convertTimeToOtherTimeZone;
67
94
  var timeZonesList = new Map([["Africa/Bangui", "W. Central Africa Standard Time"], ["Africa/Cairo", "Egypt Standard Time"], ["Africa/Casablanca", "Morocco Standard Time"], ["Africa/Harare", "South Africa Standard Time"], ["Africa/Johannesburg", "South Africa Standard Time"], ["Africa/Lagos", "W. Central Africa Standard Time"], ["Africa/Monrovia", "Greenwich Standard Time"], ["Africa/Nairobi", "E. Africa Standard Time"], ["Africa/Windhoek", "Namibia Standard Time"], ["America/Anchorage", "Alaskan Standard Time"], ["America/Argentina/San_Juan", "Argentina Standard Time"], ["America/Asuncion", "Paraguay Standard Time"], ["America/Bahia", "Bahia Standard Time"], ["America/Bogota", "SA Pacific Standard Time"], ["America/Buenos_Aires", "Argentina Standard Time"], ["America/Caracas", "Venezuela Standard Time"], ["America/Cayenne", "SA Eastern Standard Time"], ["America/Chicago", "Central Standard Time"], ["America/Chihuahua", "Mountain Standard Time (Mexico)"], ["America/Cuiaba", "Central Brazilian Standard Time"], ["America/Denver", "Mountain Standard Time"], ["America/Fortaleza", "SA Eastern Standard Time"], ["America/Godthab", "Greenland Standard Time"], ["America/Guatemala", "Central America Standard Time"], ["America/Halifax", "Atlantic Standard Time"], ["America/Indianapolis", "US Eastern Standard Time"], ["America/Indiana/Indianapolis", "US Eastern Standard Time"], ["America/La_Paz", "SA Western Standard Time"], ["America/Los_Angeles", "Pacific Standard Time"], ["America/Mexico_City", "Mexico Standard Time"], ["America/Montevideo", "Montevideo Standard Time"], ["America/New_York", "Eastern Standard Time"], ["America/Noronha", "UTC-02"], ["America/Phoenix", "US Mountain Standard Time"], ["America/Regina", "Canada Central Standard Time"], ["America/Santa_Isabel", "Pacific Standard Time (Mexico)"], ["America/Santiago", "Pacific SA Standard Time"], ["America/Sao_Paulo", "E. South America Standard Time"], ["America/St_Johns", "Newfoundland Standard Time"], ["America/Tijuana", "Pacific Standard Time"], ["Antarctica/McMurdo", "New Zealand Standard Time"], ["Atlantic/South_Georgia", "UTC-02"], ["Asia/Almaty", "Central Asia Standard Time"], ["Asia/Amman", "Jordan Standard Time"], ["Asia/Baghdad", "Arabic Standard Time"], ["Asia/Baku", "Azerbaijan Standard Time"], ["Asia/Bangkok", "SE Asia Standard Time"], ["Asia/Beirut", "Middle East Standard Time"], ["Asia/Calcutta", "India Standard Time"], ["Asia/Colombo", "Sri Lanka Standard Time"], ["Asia/Damascus", "Syria Standard Time"], ["Asia/Dhaka", "Bangladesh Standard Time"], ["Asia/Dubai", "Arabian Standard Time"], ["Asia/Irkutsk", "North Asia East Standard Time"], ["Asia/Jerusalem", "Israel Standard Time"], ["Asia/Kabul", "Afghanistan Standard Time"], ["Asia/Kamchatka", "Kamchatka Standard Time"], ["Asia/Karachi", "Pakistan Standard Time"], ["Asia/Katmandu", "Nepal Standard Time"], ["Asia/Kolkata", "India Standard Time"], ["Asia/Krasnoyarsk", "North Asia Standard Time"], ["Asia/Kuala_Lumpur", "Singapore Standard Time"], ["Asia/Kuwait", "Arab Standard Time"], ["Asia/Magadan", "Magadan Standard Time"], ["Asia/Muscat", "Arabian Standard Time"], ["Asia/Novosibirsk", "N. Central Asia Standard Time"], ["Asia/Oral", "West Asia Standard Time"], ["Asia/Rangoon", "Myanmar Standard Time"], ["Asia/Riyadh", "Arab Standard Time"], ["Asia/Seoul", "Korea Standard Time"], ["Asia/Shanghai", "China Standard Time"], ["Asia/Singapore", "Singapore Standard Time"], ["Asia/Taipei", "Taipei Standard Time"], ["Asia/Tashkent", "West Asia Standard Time"], ["Asia/Tbilisi", "Georgian Standard Time"], ["Asia/Tehran", "Iran Standard Time"], ["Asia/Tokyo", "Tokyo Standard Time"], ["Asia/Ulaanbaatar", "Ulaanbaatar Standard Time"], ["Asia/Vladivostok", "Vladivostok Standard Time"], ["Asia/Yakutsk", "Yakutsk Standard Time"], ["Asia/Yekaterinburg", "Ekaterinburg Standard Time"], ["Asia/Yerevan", "Armenian Standard Time"], ["Atlantic/Azores", "Azores Standard Time"], ["Atlantic/Cape_Verde", "Cape Verde Standard Time"], ["Atlantic/Reykjavik", "Greenwich Standard Time"], ["Australia/Adelaide", "Cen. Australia Standard Time"], ["Australia/Brisbane", "E. Australia Standard Time"], ["Australia/Darwin", "AUS Central Standard Time"], ["Australia/Hobart", "Tasmania Standard Time"], ["Australia/Perth", "W. Australia Standard Time"], ["Australia/Sydney", "AUS Eastern Standard Time"], ["UTC", "UTC"], ["Etc/GMT+11", "UTC-11"], ["Etc/GMT+12", "Dateline Standard Time"], ["Etc/GMT+2", "UTC-02"], ["Etc/GMT-12", "UTC+12"], ["Europe/Amsterdam", "W. Europe Standard Time"], ["Europe/Athens", "GTB Standard Time"], ["Europe/Belgrade", "Central Europe Standard Time"], ["Europe/Berlin", "W. Europe Standard Time"], ["Europe/Brussels", "Romance Standard Time"], ["Europe/Budapest", "Central Europe Standard Time"], ["Europe/Dublin", "GMT Standard Time"], ["Europe/Helsinki", "FLE Standard Time"], ["Europe/Istanbul", "GTB Standard Time"], ["Europe/Kiev", "FLE Standard Time"], ["Europe/London", "GMT Standard Time"], ["Europe/Minsk", "E. Europe Standard Time"], ["Europe/Moscow", "Russian Standard Time"], ["Europe/Paris", "Romance Standard Time"], ["Europe/Sarajevo", "Central European Standard Time"], ["Europe/Warsaw", "Central European Standard Time"], ["Indian/Mauritius", "Mauritius Standard Time"], ["Pacific/Apia", "Samoa Standard Time"], ["Pacific/Auckland", "New Zealand Standard Time"], ["Pacific/Fiji", "Fiji Standard Time"], ["Pacific/Guadalcanal", "Central Pacific Standard Time"], ["Pacific/Guam", "West Pacific Standard Time"], ["Pacific/Honolulu", "Hawaiian Standard Time"], ["Pacific/Pago_Pago", "UTC-11"], ["Pacific/Port_Moresby", "West Pacific Standard Time"], ["Pacific/Tongatapu", "Tonga Standard Time"]]);
68
95
  exports.timeZonesList = timeZonesList;
69
96
  ;
@@ -78,6 +105,8 @@ exports.timeZonesList = timeZonesList;
78
105
  reactHotLoader.register(getTimeZone, "getTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
79
106
  reactHotLoader.register(getTimeZoneByName, "getTimeZoneByName", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
80
107
  reactHotLoader.register(getTimeZoneName, "getTimeZoneName", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
108
+ reactHotLoader.register(convertTimeToLocalTimeZone, "convertTimeToLocalTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
109
+ reactHotLoader.register(convertTimeToOtherTimeZone, "convertTimeToOtherTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
81
110
  reactHotLoader.register(timeZonesList, "timeZonesList", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
82
111
  })();
83
112
 
@@ -100,6 +129,8 @@ exports.timeZonesList = timeZonesList;
100
129
  reactHotLoader.register(getTimeZone, "getTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
101
130
  reactHotLoader.register(getTimeZoneByName, "getTimeZoneByName", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
102
131
  reactHotLoader.register(getTimeZoneName, "getTimeZoneName", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
132
+ reactHotLoader.register(convertTimeToLocalTimeZone, "convertTimeToLocalTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
133
+ reactHotLoader.register(convertTimeToOtherTimeZone, "convertTimeToOtherTimeZone", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
103
134
  reactHotLoader.register(timeZonesList, "timeZonesList", "/home/vsts/work/1/s/src/utils/timezoneHelper.js");
104
135
  })();
105
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.3.0-dev.8",
3
+ "version": "1.3.0-dev.9",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -59,6 +59,24 @@ describe("InputField", () => {
59
59
  field_fieldName: { wasBlurred: true },
60
60
  activeForm_fieldName: { wasBlurred: true },
61
61
  },
62
+ metadata: {
63
+ lookups: {
64
+ customer: {
65
+ index: {
66
+ TimeZone: {
67
+ values: {
68
+ UTC: {
69
+ value: "UTC",
70
+ displayName: {
71
+ "en-US": "(UTC) Coordinated Universal Time",
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ },
78
+ },
79
+ },
62
80
  });
63
81
  store = {
64
82
  subscribe: () => {},
@@ -14,6 +14,24 @@ describe("DateInput", () => {
14
14
  locale: {
15
15
  locale: "en-CA",
16
16
  },
17
+ metadata: {
18
+ lookups: {
19
+ customer: {
20
+ index: {
21
+ TimeZone: {
22
+ values: {
23
+ UTC: {
24
+ value: "UTC",
25
+ displayName: {
26
+ "en-US": "(UTC) Coordinated Universal Time",
27
+ },
28
+ },
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ },
17
35
  });
18
36
 
19
37
  store = {
@@ -5,6 +5,13 @@ import DatePicker from "react-datepicker";
5
5
  import "react-datepicker/dist/react-datepicker.css";
6
6
  import TimePicker from "./TimePicker";
7
7
  import { makeStyles } from "@material-ui/core/styles";
8
+ import {
9
+ getTimeZoneByName,
10
+ convertTimeToOtherTimeZone,
11
+ convertTimeToLocalTimeZone,
12
+ } from "../../../utils/timezoneHelper";
13
+ import { namedLookupLocalizedSelector } from "../../../selectors/metadata";
14
+ import { useSelector } from "react-redux";
8
15
 
9
16
  const useStyles = makeStyles(theme => ({
10
17
  container: {
@@ -131,12 +138,18 @@ const WrappedDatePicker = ({
131
138
  ...props
132
139
  }) => {
133
140
  const classes = useStyles({ readOnly });
134
- const startDate = value ? new Date(value) : null;
141
+ const timeZoneName = getTimeZoneByName(timePickerTimeZone);
142
+ const startDate = value
143
+ ? timePickerTimeZone
144
+ ? convertTimeToLocalTimeZone(new Date(value), timeZoneName)
145
+ : new Date(value)
146
+ : null;
135
147
  const disabledCls = classNames({ [classes.disabled]: props.disabled });
148
+ const localizedTimeZoneName = useSelector(namedLookupLocalizedSelector("customer", "TimeZone", timePickerTimeZone));
136
149
 
137
150
  const updateDate = (date, metadata) => {
138
151
  if (onChange) {
139
- onChange(date, metadata);
152
+ onChange(useTime && timePickerTimeZone ? convertTimeToOtherTimeZone(date, timeZoneName) : date, metadata);
140
153
  }
141
154
  };
142
155
 
@@ -152,7 +165,7 @@ const WrappedDatePicker = ({
152
165
  showTimeInput={useTime ?? false}
153
166
  useTime={useTime ?? false}
154
167
  customTimeInput={
155
- useTime ? <TimePicker showTimeZone={showTimeZone} requestedTimeZone={timePickerTimeZone} /> : null
168
+ useTime ? <TimePicker showTimeZone={showTimeZone} requestedTimeZone={localizedTimeZoneName} /> : null
156
169
  }
157
170
  timeInputLabel={timeInputLabel ?? ""}
158
171
  readOnly={readOnly}
@@ -15,8 +15,25 @@ describe("DatePicker", () => {
15
15
  locale: {
16
16
  locale: "en-CA",
17
17
  },
18
+ metadata: {
19
+ lookups: {
20
+ customer: {
21
+ index: {
22
+ TimeZone: {
23
+ values: {
24
+ UTC: {
25
+ value: "Eastern Standard Time",
26
+ displayName: {
27
+ "en-US": "Eastern Standard Time",
28
+ },
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ },
35
+ },
18
36
  });
19
-
20
37
  store = {
21
38
  subscribe: () => {},
22
39
  dispatch: () => {},
@@ -311,6 +328,103 @@ describe("DatePicker", () => {
311
328
 
312
329
  input.at(0).simulate("change", event);
313
330
  });
331
+
332
+ it("should call onChange prop with timezone", () => {
333
+ const onChangeMock = jest.fn();
334
+ const date = new Date("2020-06-30T00:00:00");
335
+ const event = {
336
+ preventDefault() {},
337
+ target: { value: "" },
338
+ };
339
+ const requestTimeZone = "Eastern Standard Time";
340
+
341
+ const component = (
342
+ <TestWrapper provider={{ store }} intlProvider>
343
+ <DatePicker
344
+ onChange={onChangeMock}
345
+ value={date}
346
+ useTime={true}
347
+ useDate={false}
348
+ showTimeSelectOnly={true}
349
+ timePickerTimeZone={requestTimeZone}
350
+ />
351
+ </TestWrapper>
352
+ );
353
+ const mountedComponent = mount(component);
354
+
355
+ const input = mountedComponent.find("input");
356
+ input.at(0).simulate("change", event);
357
+ expect(onChangeMock.mock.calls.length, "to equal", 1);
358
+ });
359
+
360
+ it("should call onChange prop with null timezone", () => {
361
+ const onChangeMock = jest.fn();
362
+ const date = new Date("2020-06-30T00:00:00");
363
+ const event = {
364
+ preventDefault() {},
365
+ target: { value: "" },
366
+ };
367
+
368
+ const component = (
369
+ <TestWrapper provider={{ store }} intlProvider>
370
+ <DatePicker
371
+ onChange={onChangeMock}
372
+ value={date}
373
+ useTime={true}
374
+ useDate={false}
375
+ showTimeSelectOnly={true}
376
+ timePickerTimeZone={null}
377
+ />
378
+ </TestWrapper>
379
+ );
380
+ const mountedComponent = mount(component);
381
+
382
+ const input = mountedComponent.find("input");
383
+ input.at(0).simulate("change", event);
384
+ expect(onChangeMock.mock.calls.length, "to equal", 1);
385
+ });
386
+
387
+ it("should call onChange prop with timezone without date value", () => {
388
+ const onChangeMock = jest.fn();
389
+ const event = {
390
+ preventDefault() {},
391
+ target: { value: "" },
392
+ };
393
+ const requestTimeZone = "Eastern Standard Time";
394
+ const component = (
395
+ <TestWrapper provider={{ store }} intlProvider>
396
+ <DatePicker
397
+ onChange={onChangeMock}
398
+ useTime={true}
399
+ useDate={false}
400
+ showTimeSelectOnly={true}
401
+ timePickerTimeZone={requestTimeZone}
402
+ />
403
+ </TestWrapper>
404
+ );
405
+ const mountedComponent = mount(component);
406
+
407
+ const input = mountedComponent.find("input");
408
+ input.at(0).simulate("change", event);
409
+ });
410
+
411
+ it("should call onChange prop with timezone and not use time", () => {
412
+ const date = new Date("2020-06-30T00:00:00");
413
+ const event = {
414
+ preventDefault() {},
415
+ target: { value: "" },
416
+ };
417
+ const requestTimeZone = "Eastern Standard Time";
418
+ const component = (
419
+ <TestWrapper provider={{ store }} intlProvider>
420
+ <DatePicker value={date} useDate={false} showTimeSelectOnly={true} timePickerTimeZone={requestTimeZone} />
421
+ </TestWrapper>
422
+ );
423
+ const mountedComponent = mount(component);
424
+
425
+ const input = mountedComponent.find("input");
426
+ input.at(0).simulate("change", event);
427
+ });
314
428
  });
315
429
 
316
430
  describe("createFormat", () => {
@@ -1,3 +1,5 @@
1
+ import moment from "moment-timezone";
2
+
1
3
  export const getTimeZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
2
4
 
3
5
  export const getTimeZoneByName = name => {
@@ -14,6 +16,22 @@ export const getTimeZoneName = () => {
14
16
  return timezoneName;
15
17
  };
16
18
 
19
+ //converting time from other timezone to local
20
+ export const convertTimeToLocalTimeZone = (date, timezone) => {
21
+ const dateWithoutZone = moment.tz(date, timezone).format("YYYY-MM-DDTHH:mm:ss.SSS");
22
+ const localZone = moment(dateWithoutZone).format("Z");
23
+ const dateWithLocalZone = [dateWithoutZone, localZone].join("");
24
+ return new Date(dateWithLocalZone);
25
+ };
26
+
27
+ //converting time from local timezone to other
28
+ export const convertTimeToOtherTimeZone = (date, timezone) => {
29
+ const dateWithoutZone = moment(date).format("YYYY-MM-DDTHH:mm:ss.SSS");
30
+ const otherZone = moment.tz(date, timezone).format("Z");
31
+ const dateWithOtherZone = [dateWithoutZone, otherZone].join("");
32
+ return new Date(dateWithOtherZone);
33
+ };
34
+
17
35
  export const timeZonesList = new Map([
18
36
  ["Africa/Bangui", "W. Central Africa Standard Time"],
19
37
  ["Africa/Cairo", "Egypt Standard Time"],
@@ -1,4 +1,10 @@
1
- import { getTimeZone, getTimeZoneByName, getTimeZoneName } from "./timezoneHelper";
1
+ import {
2
+ getTimeZone,
3
+ getTimeZoneByName,
4
+ getTimeZoneName,
5
+ convertTimeToLocalTimeZone,
6
+ convertTimeToOtherTimeZone,
7
+ } from "./timezoneHelper";
2
8
 
3
9
  describe("Timezone Helper", () => {
4
10
  beforeEach(() => {
@@ -30,4 +36,18 @@ describe("Timezone Helper", () => {
30
36
  it("Retrieves user timezone name", () => {
31
37
  expect(getTimeZoneName, "called with", [], "to satisfy", "W. Europe Standard Time");
32
38
  });
39
+
40
+ it("Retrieves user local timezone date", () => {
41
+ const timezoneName = "America/New_York";
42
+ const date = "Mon Apr 04 2022 13:00:00 GMT+0300 (Eastern European Summer Time)";
43
+ const expectedDate = new Date("2022-04-04T09:00:00Z");
44
+ expect(convertTimeToLocalTimeZone, "called with", [date, timezoneName], "to satisfy", expectedDate);
45
+ });
46
+
47
+ it("Retrieves user other timezone date", () => {
48
+ const timezoneName = "America/New_York";
49
+ const date = "Mon Apr 04 2022 03:00:00 GMT+0300 (Eastern European Summer Time)";
50
+ const expectedDate = new Date("2022-04-04T04:00:00Z");
51
+ expect(convertTimeToOtherTimeZone, "called with", [date, timezoneName], "to satisfy", expectedDate);
52
+ });
33
53
  });