orc-shared 1.3.0-dev.8 → 1.4.0-dev.1
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/dist/components/MaterialUI/Inputs/DatePicker.js +18 -8
- package/dist/utils/timezoneHelper.js +33 -2
- package/package.json +3 -3
- package/src/components/Form/InputField.test.js +18 -0
- package/src/components/Form/Inputs/Date.test.js +18 -0
- package/src/components/MaterialUI/Inputs/DatePicker.js +17 -3
- package/src/components/MaterialUI/Inputs/DatePicker.test.js +143 -1
- package/src/utils/timezoneHelper.js +18 -0
- package/src/utils/timezoneHelper.test.js +21 -1
|
@@ -17,7 +17,13 @@ var _TimePicker = _interopRequireDefault(require("./TimePicker"));
|
|
|
17
17
|
|
|
18
18
|
var _styles = require("@material-ui/core/styles");
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _timezoneHelper = require("../../../utils/timezoneHelper");
|
|
21
|
+
|
|
22
|
+
var _metadata = require("../../../selectors/metadata");
|
|
23
|
+
|
|
24
|
+
var _reactRedux = require("react-redux");
|
|
25
|
+
|
|
26
|
+
var _excluded = ["value", "useTime", "useDate", "onChange", "useTimeZone", "dateFormat", "showTimeZone", "timeInputLabel", "readOnly", "showTimeSelectOnly", "metadata", "timePickerTimeZone", "error"];
|
|
21
27
|
|
|
22
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
29
|
|
|
@@ -172,6 +178,8 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
|
|
|
172
178
|
_ref$useDate = _ref.useDate,
|
|
173
179
|
useDate = _ref$useDate === void 0 ? true : _ref$useDate,
|
|
174
180
|
onChange = _ref.onChange,
|
|
181
|
+
_ref$useTimeZone = _ref.useTimeZone,
|
|
182
|
+
useTimeZone = _ref$useTimeZone === void 0 ? false : _ref$useTimeZone,
|
|
175
183
|
dateFormat = _ref.dateFormat,
|
|
176
184
|
showTimeZone = _ref.showTimeZone,
|
|
177
185
|
timeInputLabel = _ref.timeInputLabel,
|
|
@@ -185,12 +193,14 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
|
|
|
185
193
|
var classes = useStyles({
|
|
186
194
|
readOnly: readOnly
|
|
187
195
|
});
|
|
188
|
-
var
|
|
196
|
+
var timeZoneName = (0, _timezoneHelper.getTimeZoneByName)(timePickerTimeZone);
|
|
197
|
+
var startDate = value ? timePickerTimeZone && useTimeZone ? (0, _timezoneHelper.convertTimeToLocalTimeZone)(new Date(value), timeZoneName) : new Date(value) : null;
|
|
189
198
|
var disabledCls = (0, _classnames.default)(_defineProperty({}, classes.disabled, props.disabled));
|
|
199
|
+
var localizedTimeZoneName = (0, _reactRedux.useSelector)((0, _metadata.namedLookupLocalizedSelector)("customer", "TimeZone", timePickerTimeZone));
|
|
190
200
|
|
|
191
201
|
var updateDate = function updateDate(date, metadata) {
|
|
192
202
|
if (onChange) {
|
|
193
|
-
onChange(date, metadata);
|
|
203
|
+
onChange(useTimeZone && timePickerTimeZone ? (0, _timezoneHelper.convertTimeToOtherTimeZone)(date, timeZoneName) : date, metadata);
|
|
194
204
|
}
|
|
195
205
|
};
|
|
196
206
|
|
|
@@ -210,7 +220,7 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
|
|
|
210
220
|
useTime: useTime != null ? useTime : false,
|
|
211
221
|
customTimeInput: useTime ? /*#__PURE__*/_react.default.createElement(_TimePicker.default, {
|
|
212
222
|
showTimeZone: showTimeZone,
|
|
213
|
-
requestedTimeZone:
|
|
223
|
+
requestedTimeZone: localizedTimeZoneName
|
|
214
224
|
}) : null,
|
|
215
225
|
timeInputLabel: timeInputLabel != null ? timeInputLabel : "",
|
|
216
226
|
readOnly: readOnly,
|
|
@@ -225,12 +235,12 @@ var WrappedDatePicker = function WrappedDatePicker(_ref) {
|
|
|
225
235
|
}, error));
|
|
226
236
|
};
|
|
227
237
|
|
|
228
|
-
__signature__(WrappedDatePicker, "useStyles{classes}", function () {
|
|
229
|
-
return [useStyles];
|
|
238
|
+
__signature__(WrappedDatePicker, "useStyles{classes}\nuseSelector{localizedTimeZoneName}", function () {
|
|
239
|
+
return [useStyles, _reactRedux.useSelector];
|
|
230
240
|
});
|
|
231
241
|
|
|
232
|
-
__signature__(WrappedDatePicker, "useStyles{classes}", function () {
|
|
233
|
-
return [useStyles];
|
|
242
|
+
__signature__(WrappedDatePicker, "useStyles{classes}\nuseSelector{localizedTimeZoneName}", function () {
|
|
243
|
+
return [useStyles, _reactRedux.useSelector];
|
|
234
244
|
});
|
|
235
245
|
|
|
236
246
|
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
|
+
"version": "1.4.0-dev.1",
|
|
4
4
|
"description": "Shared code for Orckestra applications",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"orc-scripts": "1.
|
|
52
|
+
"orc-scripts": "1.5.0-dev.1"
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"lint-staged": {
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"orc-scripts": "1.
|
|
72
|
+
"orc-scripts": "1.5.0-dev.1"
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -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: {
|
|
@@ -120,6 +127,7 @@ const WrappedDatePicker = ({
|
|
|
120
127
|
useTime,
|
|
121
128
|
useDate = true,
|
|
122
129
|
onChange,
|
|
130
|
+
useTimeZone = false,
|
|
123
131
|
dateFormat,
|
|
124
132
|
showTimeZone,
|
|
125
133
|
timeInputLabel,
|
|
@@ -131,12 +139,18 @@ const WrappedDatePicker = ({
|
|
|
131
139
|
...props
|
|
132
140
|
}) => {
|
|
133
141
|
const classes = useStyles({ readOnly });
|
|
134
|
-
const
|
|
142
|
+
const timeZoneName = getTimeZoneByName(timePickerTimeZone);
|
|
143
|
+
const startDate = value
|
|
144
|
+
? timePickerTimeZone && useTimeZone
|
|
145
|
+
? convertTimeToLocalTimeZone(new Date(value), timeZoneName)
|
|
146
|
+
: new Date(value)
|
|
147
|
+
: null;
|
|
135
148
|
const disabledCls = classNames({ [classes.disabled]: props.disabled });
|
|
149
|
+
const localizedTimeZoneName = useSelector(namedLookupLocalizedSelector("customer", "TimeZone", timePickerTimeZone));
|
|
136
150
|
|
|
137
151
|
const updateDate = (date, metadata) => {
|
|
138
152
|
if (onChange) {
|
|
139
|
-
onChange(date, metadata);
|
|
153
|
+
onChange(useTimeZone && timePickerTimeZone ? convertTimeToOtherTimeZone(date, timeZoneName) : date, metadata);
|
|
140
154
|
}
|
|
141
155
|
};
|
|
142
156
|
|
|
@@ -152,7 +166,7 @@ const WrappedDatePicker = ({
|
|
|
152
166
|
showTimeInput={useTime ?? false}
|
|
153
167
|
useTime={useTime ?? false}
|
|
154
168
|
customTimeInput={
|
|
155
|
-
useTime ? <TimePicker showTimeZone={showTimeZone} requestedTimeZone={
|
|
169
|
+
useTime ? <TimePicker showTimeZone={showTimeZone} requestedTimeZone={localizedTimeZoneName} /> : null
|
|
156
170
|
}
|
|
157
171
|
timeInputLabel={timeInputLabel ?? ""}
|
|
158
172
|
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,131 @@ 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
|
+
});
|
|
428
|
+
|
|
429
|
+
it("should call onChange prop with useTimeZone", () => {
|
|
430
|
+
const onChangeMock = jest.fn();
|
|
431
|
+
const date = new Date("2020-06-30T00:00:00");
|
|
432
|
+
const event = {
|
|
433
|
+
preventDefault() {},
|
|
434
|
+
target: { value: "" },
|
|
435
|
+
};
|
|
436
|
+
const requestTimeZone = "Eastern Standard Time";
|
|
437
|
+
const component = (
|
|
438
|
+
<TestWrapper provider={{ store }} intlProvider>
|
|
439
|
+
<DatePicker
|
|
440
|
+
onChange={onChangeMock}
|
|
441
|
+
value={date}
|
|
442
|
+
useTime={true}
|
|
443
|
+
useDate={false}
|
|
444
|
+
useTimeZone={true}
|
|
445
|
+
showTimeSelectOnly={true}
|
|
446
|
+
timePickerTimeZone={requestTimeZone}
|
|
447
|
+
/>
|
|
448
|
+
</TestWrapper>
|
|
449
|
+
);
|
|
450
|
+
const mountedComponent = mount(component);
|
|
451
|
+
|
|
452
|
+
const input = mountedComponent.find("input");
|
|
453
|
+
input.at(0).simulate("change", event);
|
|
454
|
+
expect(onChangeMock.mock.calls.length, "to equal", 1);
|
|
455
|
+
});
|
|
314
456
|
});
|
|
315
457
|
|
|
316
458
|
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 {
|
|
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
|
});
|