@commercetools-uikit/calendar-time-utils 20.2.3 → 20.3.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.
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
6
6
|
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
7
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
7
8
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
8
9
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
9
10
|
var _Array$from = require('@babel/runtime-corejs3/core-js-stable/array/from');
|
|
10
11
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
12
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
11
13
|
var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
|
|
12
14
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
13
15
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
@@ -17,10 +19,12 @@ var utils = require('@commercetools-uikit/utils');
|
|
|
17
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
20
|
|
|
19
21
|
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
22
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
20
23
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
21
24
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
22
25
|
var _Array$from__default = /*#__PURE__*/_interopDefault(_Array$from);
|
|
23
26
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
27
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
24
28
|
var _Map__default = /*#__PURE__*/_interopDefault(_Map);
|
|
25
29
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
26
30
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
@@ -112,7 +116,7 @@ const formatDefaultTime = (time, locale) => {
|
|
|
112
116
|
});
|
|
113
117
|
return moment__default["default"](today).locale(locale).format('LT'); // 5:13 PM
|
|
114
118
|
} else {
|
|
115
|
-
process.env.NODE_ENV !== "production" ? utils.warning(false,
|
|
119
|
+
process.env.NODE_ENV !== "production" ? utils.warning(false, "DataTimeInput: the specified defaultDaySelectionTime '".concat(time, "' is not supported. The format should be hh:mm, e.g. 11:10. Using 00:00 as default time.")) : void 0;
|
|
116
120
|
today.set({
|
|
117
121
|
hour: 0,
|
|
118
122
|
minute: 0
|
|
@@ -127,9 +131,10 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
127
131
|
return date.format('LT'); // 5:13 PM
|
|
128
132
|
};
|
|
129
133
|
const formatDate = (day, locale, timeZone) => {
|
|
134
|
+
var _context;
|
|
130
135
|
const date = moment__default["default"](day, moment__default["default"].ISO_8601, locale).tz(timeZone).format('L');
|
|
131
136
|
const time = formatTime(day, locale, timeZone);
|
|
132
|
-
return
|
|
137
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(date, " ")).call(_context, time);
|
|
133
138
|
};
|
|
134
139
|
const getDateInMonth = (day, timeZone) => moment__default["default"].tz(day, timeZone).date();
|
|
135
140
|
const getToday = timeZone => moment__default["default"].tz(timeZone).startOf('day').toISOString();
|
|
@@ -153,11 +158,11 @@ const isSameDay = (a, b) => moment__default["default"](a).isSame(b, 'day');
|
|
|
153
158
|
const getCalendarDayLabel = (day, timeZone) => moment__default["default"].tz(day, timeZone).format('D');
|
|
154
159
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
155
160
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
156
|
-
var
|
|
161
|
+
var _context2;
|
|
157
162
|
const parsedTime = utils.parseTime(timeString);
|
|
158
|
-
return _mapInstanceProperty__default["default"](
|
|
163
|
+
return _mapInstanceProperty__default["default"](_context2 = _Array$from__default["default"]({
|
|
159
164
|
length: getDaysInMonth(day, timeZone)
|
|
160
|
-
})).call(
|
|
165
|
+
})).call(_context2, (_, i) => {
|
|
161
166
|
const dayOfMonth = i + 1;
|
|
162
167
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
163
168
|
if (parsedTime) {
|
|
@@ -191,31 +196,79 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
191
196
|
}
|
|
192
197
|
return '';
|
|
193
198
|
};
|
|
199
|
+
const getIntlDatePattern = locale => {
|
|
200
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
201
|
+
year: 'numeric',
|
|
202
|
+
month: '2-digit',
|
|
203
|
+
day: '2-digit'
|
|
204
|
+
});
|
|
205
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15));
|
|
206
|
+
return _mapInstanceProperty__default["default"](parts).call(parts, part => {
|
|
207
|
+
switch (part.type) {
|
|
208
|
+
case 'day':
|
|
209
|
+
return 'DD';
|
|
210
|
+
case 'month':
|
|
211
|
+
return 'MM';
|
|
212
|
+
case 'year':
|
|
213
|
+
return 'YYYY';
|
|
214
|
+
case 'literal':
|
|
215
|
+
return part.value;
|
|
216
|
+
default:
|
|
217
|
+
return '';
|
|
218
|
+
}
|
|
219
|
+
}).join('');
|
|
220
|
+
};
|
|
221
|
+
const getIntlTimePattern = locale => {
|
|
222
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
223
|
+
timeStyle: 'short'
|
|
224
|
+
});
|
|
225
|
+
// Use 2:30 AM so the hour is single-digit, allowing us to detect padding
|
|
226
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15, 2, 30));
|
|
227
|
+
const hasDayPeriod = _someInstanceProperty__default["default"](parts).call(parts, p => p.type === 'dayPeriod');
|
|
228
|
+
return _mapInstanceProperty__default["default"](parts).call(parts, part => {
|
|
229
|
+
switch (part.type) {
|
|
230
|
+
case 'hour':
|
|
231
|
+
{
|
|
232
|
+
const padded = part.value.length === 2;
|
|
233
|
+
if (hasDayPeriod) {
|
|
234
|
+
return padded ? 'hh' : 'h';
|
|
235
|
+
}
|
|
236
|
+
return padded ? 'HH' : 'H';
|
|
237
|
+
}
|
|
238
|
+
case 'minute':
|
|
239
|
+
return 'mm';
|
|
240
|
+
case 'dayPeriod':
|
|
241
|
+
return 'A';
|
|
242
|
+
case 'literal':
|
|
243
|
+
// Normalize unicode whitespace (e.g. U+202F narrow no-break space)
|
|
244
|
+
// to regular spaces for consistent placeholder text
|
|
245
|
+
return part.value.replace(/\s/g, ' ');
|
|
246
|
+
default:
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
249
|
+
}).join('');
|
|
250
|
+
};
|
|
194
251
|
const localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
195
252
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
253
|
+
var _context3, _context4;
|
|
196
254
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
197
|
-
const key =
|
|
255
|
+
const key = _concatInstanceProperty__default["default"](_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
198
256
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
199
257
|
return localizedDateFormatPatternCache.get(key);
|
|
200
258
|
}
|
|
201
|
-
|
|
202
|
-
// References:
|
|
203
|
-
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
204
|
-
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
205
|
-
const localeData = moment__default["default"]().locale(locale).localeData();
|
|
206
259
|
let localizedFormat = '';
|
|
207
260
|
switch (formatType) {
|
|
208
261
|
case 'date':
|
|
209
|
-
localizedFormat =
|
|
262
|
+
localizedFormat = getIntlDatePattern(locale);
|
|
210
263
|
break;
|
|
211
264
|
case 'time':
|
|
212
|
-
localizedFormat =
|
|
265
|
+
localizedFormat = getIntlTimePattern(locale);
|
|
213
266
|
break;
|
|
214
267
|
case 'full':
|
|
215
|
-
localizedFormat =
|
|
268
|
+
localizedFormat = _concatInstanceProperty__default["default"](_context4 = "".concat(getIntlDatePattern(locale), " - ")).call(_context4, getIntlTimePattern(locale));
|
|
216
269
|
break;
|
|
217
270
|
default:
|
|
218
|
-
throw new Error(
|
|
271
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
219
272
|
}
|
|
220
273
|
|
|
221
274
|
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
@@ -226,7 +279,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
226
279
|
const localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
227
280
|
|
|
228
281
|
// In case we don't have a translation for the locale, we fallback to the
|
|
229
|
-
// pattern
|
|
282
|
+
// Intl-derived pattern.
|
|
230
283
|
let pattern = localizedFormat;
|
|
231
284
|
if (localeMappings && localeMappings.length > 0) {
|
|
232
285
|
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
@@ -241,7 +294,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
241
294
|
};
|
|
242
295
|
|
|
243
296
|
// NOTE: This string will be replaced on build time with the package version.
|
|
244
|
-
var version = "20.
|
|
297
|
+
var version = "20.3.1";
|
|
245
298
|
|
|
246
299
|
exports.changeDateInMonth = changeDateInMonth;
|
|
247
300
|
exports.changeMonth = changeMonth;
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
6
6
|
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
7
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
7
8
|
var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
|
|
8
9
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
9
10
|
var _Array$from = require('@babel/runtime-corejs3/core-js-stable/array/from');
|
|
10
11
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
12
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
11
13
|
var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
|
|
12
14
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
13
15
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
@@ -17,10 +19,12 @@ var utils = require('@commercetools-uikit/utils');
|
|
|
17
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
18
20
|
|
|
19
21
|
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
22
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
20
23
|
var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
|
|
21
24
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
22
25
|
var _Array$from__default = /*#__PURE__*/_interopDefault(_Array$from);
|
|
23
26
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
27
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
24
28
|
var _Map__default = /*#__PURE__*/_interopDefault(_Map);
|
|
25
29
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
26
30
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
@@ -126,9 +130,10 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
126
130
|
return date.format('LT'); // 5:13 PM
|
|
127
131
|
};
|
|
128
132
|
const formatDate = (day, locale, timeZone) => {
|
|
133
|
+
var _context;
|
|
129
134
|
const date = moment__default["default"](day, moment__default["default"].ISO_8601, locale).tz(timeZone).format('L');
|
|
130
135
|
const time = formatTime(day, locale, timeZone);
|
|
131
|
-
return
|
|
136
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(date, " ")).call(_context, time);
|
|
132
137
|
};
|
|
133
138
|
const getDateInMonth = (day, timeZone) => moment__default["default"].tz(day, timeZone).date();
|
|
134
139
|
const getToday = timeZone => moment__default["default"].tz(timeZone).startOf('day').toISOString();
|
|
@@ -152,11 +157,11 @@ const isSameDay = (a, b) => moment__default["default"](a).isSame(b, 'day');
|
|
|
152
157
|
const getCalendarDayLabel = (day, timeZone) => moment__default["default"].tz(day, timeZone).format('D');
|
|
153
158
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
154
159
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
155
|
-
var
|
|
160
|
+
var _context2;
|
|
156
161
|
const parsedTime = utils.parseTime(timeString);
|
|
157
|
-
return _mapInstanceProperty__default["default"](
|
|
162
|
+
return _mapInstanceProperty__default["default"](_context2 = _Array$from__default["default"]({
|
|
158
163
|
length: getDaysInMonth(day, timeZone)
|
|
159
|
-
})).call(
|
|
164
|
+
})).call(_context2, (_, i) => {
|
|
160
165
|
const dayOfMonth = i + 1;
|
|
161
166
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
162
167
|
if (parsedTime) {
|
|
@@ -190,31 +195,79 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
190
195
|
}
|
|
191
196
|
return '';
|
|
192
197
|
};
|
|
198
|
+
const getIntlDatePattern = locale => {
|
|
199
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
200
|
+
year: 'numeric',
|
|
201
|
+
month: '2-digit',
|
|
202
|
+
day: '2-digit'
|
|
203
|
+
});
|
|
204
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15));
|
|
205
|
+
return _mapInstanceProperty__default["default"](parts).call(parts, part => {
|
|
206
|
+
switch (part.type) {
|
|
207
|
+
case 'day':
|
|
208
|
+
return 'DD';
|
|
209
|
+
case 'month':
|
|
210
|
+
return 'MM';
|
|
211
|
+
case 'year':
|
|
212
|
+
return 'YYYY';
|
|
213
|
+
case 'literal':
|
|
214
|
+
return part.value;
|
|
215
|
+
default:
|
|
216
|
+
return '';
|
|
217
|
+
}
|
|
218
|
+
}).join('');
|
|
219
|
+
};
|
|
220
|
+
const getIntlTimePattern = locale => {
|
|
221
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
222
|
+
timeStyle: 'short'
|
|
223
|
+
});
|
|
224
|
+
// Use 2:30 AM so the hour is single-digit, allowing us to detect padding
|
|
225
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15, 2, 30));
|
|
226
|
+
const hasDayPeriod = _someInstanceProperty__default["default"](parts).call(parts, p => p.type === 'dayPeriod');
|
|
227
|
+
return _mapInstanceProperty__default["default"](parts).call(parts, part => {
|
|
228
|
+
switch (part.type) {
|
|
229
|
+
case 'hour':
|
|
230
|
+
{
|
|
231
|
+
const padded = part.value.length === 2;
|
|
232
|
+
if (hasDayPeriod) {
|
|
233
|
+
return padded ? 'hh' : 'h';
|
|
234
|
+
}
|
|
235
|
+
return padded ? 'HH' : 'H';
|
|
236
|
+
}
|
|
237
|
+
case 'minute':
|
|
238
|
+
return 'mm';
|
|
239
|
+
case 'dayPeriod':
|
|
240
|
+
return 'A';
|
|
241
|
+
case 'literal':
|
|
242
|
+
// Normalize unicode whitespace (e.g. U+202F narrow no-break space)
|
|
243
|
+
// to regular spaces for consistent placeholder text
|
|
244
|
+
return part.value.replace(/\s/g, ' ');
|
|
245
|
+
default:
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
}).join('');
|
|
249
|
+
};
|
|
193
250
|
const localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
194
251
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
252
|
+
var _context3, _context4;
|
|
195
253
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
196
|
-
const key =
|
|
254
|
+
const key = _concatInstanceProperty__default["default"](_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
197
255
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
198
256
|
return localizedDateFormatPatternCache.get(key);
|
|
199
257
|
}
|
|
200
|
-
|
|
201
|
-
// References:
|
|
202
|
-
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
203
|
-
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
204
|
-
const localeData = moment__default["default"]().locale(locale).localeData();
|
|
205
258
|
let localizedFormat = '';
|
|
206
259
|
switch (formatType) {
|
|
207
260
|
case 'date':
|
|
208
|
-
localizedFormat =
|
|
261
|
+
localizedFormat = getIntlDatePattern(locale);
|
|
209
262
|
break;
|
|
210
263
|
case 'time':
|
|
211
|
-
localizedFormat =
|
|
264
|
+
localizedFormat = getIntlTimePattern(locale);
|
|
212
265
|
break;
|
|
213
266
|
case 'full':
|
|
214
|
-
localizedFormat =
|
|
267
|
+
localizedFormat = _concatInstanceProperty__default["default"](_context4 = "".concat(getIntlDatePattern(locale), " - ")).call(_context4, getIntlTimePattern(locale));
|
|
215
268
|
break;
|
|
216
269
|
default:
|
|
217
|
-
throw new Error(
|
|
270
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
218
271
|
}
|
|
219
272
|
|
|
220
273
|
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
@@ -225,7 +278,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
225
278
|
const localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
226
279
|
|
|
227
280
|
// In case we don't have a translation for the locale, we fallback to the
|
|
228
|
-
// pattern
|
|
281
|
+
// Intl-derived pattern.
|
|
229
282
|
let pattern = localizedFormat;
|
|
230
283
|
if (localeMappings && localeMappings.length > 0) {
|
|
231
284
|
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
@@ -240,7 +293,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
240
293
|
};
|
|
241
294
|
|
|
242
295
|
// NOTE: This string will be replaced on build time with the package version.
|
|
243
|
-
var version = "20.
|
|
296
|
+
var version = "20.3.1";
|
|
244
297
|
|
|
245
298
|
exports.changeDateInMonth = changeDateInMonth;
|
|
246
299
|
exports.changeMonth = changeMonth;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
2
2
|
import _parseInt from '@babel/runtime-corejs3/core-js-stable/parse-int';
|
|
3
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
3
4
|
import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
|
|
4
5
|
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
5
6
|
import _Array$from from '@babel/runtime-corejs3/core-js-stable/array/from';
|
|
6
7
|
import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
|
|
8
|
+
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
7
9
|
import _Map from '@babel/runtime-corejs3/core-js-stable/map';
|
|
8
10
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
9
11
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
@@ -96,7 +98,7 @@ const formatDefaultTime = (time, locale) => {
|
|
|
96
98
|
});
|
|
97
99
|
return moment(today).locale(locale).format('LT'); // 5:13 PM
|
|
98
100
|
} else {
|
|
99
|
-
process.env.NODE_ENV !== "production" ? warning(false,
|
|
101
|
+
process.env.NODE_ENV !== "production" ? warning(false, "DataTimeInput: the specified defaultDaySelectionTime '".concat(time, "' is not supported. The format should be hh:mm, e.g. 11:10. Using 00:00 as default time.")) : void 0;
|
|
100
102
|
today.set({
|
|
101
103
|
hour: 0,
|
|
102
104
|
minute: 0
|
|
@@ -111,9 +113,10 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
111
113
|
return date.format('LT'); // 5:13 PM
|
|
112
114
|
};
|
|
113
115
|
const formatDate = (day, locale, timeZone) => {
|
|
116
|
+
var _context;
|
|
114
117
|
const date = moment(day, moment.ISO_8601, locale).tz(timeZone).format('L');
|
|
115
118
|
const time = formatTime(day, locale, timeZone);
|
|
116
|
-
return
|
|
119
|
+
return _concatInstanceProperty(_context = "".concat(date, " ")).call(_context, time);
|
|
117
120
|
};
|
|
118
121
|
const getDateInMonth = (day, timeZone) => moment.tz(day, timeZone).date();
|
|
119
122
|
const getToday = timeZone => moment.tz(timeZone).startOf('day').toISOString();
|
|
@@ -137,11 +140,11 @@ const isSameDay = (a, b) => moment(a).isSame(b, 'day');
|
|
|
137
140
|
const getCalendarDayLabel = (day, timeZone) => moment.tz(day, timeZone).format('D');
|
|
138
141
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
139
142
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
140
|
-
var
|
|
143
|
+
var _context2;
|
|
141
144
|
const parsedTime = parseTime(timeString);
|
|
142
|
-
return _mapInstanceProperty(
|
|
145
|
+
return _mapInstanceProperty(_context2 = _Array$from({
|
|
143
146
|
length: getDaysInMonth(day, timeZone)
|
|
144
|
-
})).call(
|
|
147
|
+
})).call(_context2, (_, i) => {
|
|
145
148
|
const dayOfMonth = i + 1;
|
|
146
149
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
147
150
|
if (parsedTime) {
|
|
@@ -175,31 +178,79 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
175
178
|
}
|
|
176
179
|
return '';
|
|
177
180
|
};
|
|
181
|
+
const getIntlDatePattern = locale => {
|
|
182
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
183
|
+
year: 'numeric',
|
|
184
|
+
month: '2-digit',
|
|
185
|
+
day: '2-digit'
|
|
186
|
+
});
|
|
187
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15));
|
|
188
|
+
return _mapInstanceProperty(parts).call(parts, part => {
|
|
189
|
+
switch (part.type) {
|
|
190
|
+
case 'day':
|
|
191
|
+
return 'DD';
|
|
192
|
+
case 'month':
|
|
193
|
+
return 'MM';
|
|
194
|
+
case 'year':
|
|
195
|
+
return 'YYYY';
|
|
196
|
+
case 'literal':
|
|
197
|
+
return part.value;
|
|
198
|
+
default:
|
|
199
|
+
return '';
|
|
200
|
+
}
|
|
201
|
+
}).join('');
|
|
202
|
+
};
|
|
203
|
+
const getIntlTimePattern = locale => {
|
|
204
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
205
|
+
timeStyle: 'short'
|
|
206
|
+
});
|
|
207
|
+
// Use 2:30 AM so the hour is single-digit, allowing us to detect padding
|
|
208
|
+
const parts = formatter.formatToParts(new Date(2020, 0, 15, 2, 30));
|
|
209
|
+
const hasDayPeriod = _someInstanceProperty(parts).call(parts, p => p.type === 'dayPeriod');
|
|
210
|
+
return _mapInstanceProperty(parts).call(parts, part => {
|
|
211
|
+
switch (part.type) {
|
|
212
|
+
case 'hour':
|
|
213
|
+
{
|
|
214
|
+
const padded = part.value.length === 2;
|
|
215
|
+
if (hasDayPeriod) {
|
|
216
|
+
return padded ? 'hh' : 'h';
|
|
217
|
+
}
|
|
218
|
+
return padded ? 'HH' : 'H';
|
|
219
|
+
}
|
|
220
|
+
case 'minute':
|
|
221
|
+
return 'mm';
|
|
222
|
+
case 'dayPeriod':
|
|
223
|
+
return 'A';
|
|
224
|
+
case 'literal':
|
|
225
|
+
// Normalize unicode whitespace (e.g. U+202F narrow no-break space)
|
|
226
|
+
// to regular spaces for consistent placeholder text
|
|
227
|
+
return part.value.replace(/\s/g, ' ');
|
|
228
|
+
default:
|
|
229
|
+
return '';
|
|
230
|
+
}
|
|
231
|
+
}).join('');
|
|
232
|
+
};
|
|
178
233
|
const localizedDateFormatPatternCache = new _Map();
|
|
179
234
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
235
|
+
var _context3, _context4;
|
|
180
236
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
181
|
-
const key =
|
|
237
|
+
const key = _concatInstanceProperty(_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
182
238
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
183
239
|
return localizedDateFormatPatternCache.get(key);
|
|
184
240
|
}
|
|
185
|
-
|
|
186
|
-
// References:
|
|
187
|
-
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
188
|
-
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
189
|
-
const localeData = moment().locale(locale).localeData();
|
|
190
241
|
let localizedFormat = '';
|
|
191
242
|
switch (formatType) {
|
|
192
243
|
case 'date':
|
|
193
|
-
localizedFormat =
|
|
244
|
+
localizedFormat = getIntlDatePattern(locale);
|
|
194
245
|
break;
|
|
195
246
|
case 'time':
|
|
196
|
-
localizedFormat =
|
|
247
|
+
localizedFormat = getIntlTimePattern(locale);
|
|
197
248
|
break;
|
|
198
249
|
case 'full':
|
|
199
|
-
localizedFormat =
|
|
250
|
+
localizedFormat = _concatInstanceProperty(_context4 = "".concat(getIntlDatePattern(locale), " - ")).call(_context4, getIntlTimePattern(locale));
|
|
200
251
|
break;
|
|
201
252
|
default:
|
|
202
|
-
throw new Error(
|
|
253
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
203
254
|
}
|
|
204
255
|
|
|
205
256
|
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
@@ -210,7 +261,7 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
210
261
|
const localeMappings = _Object$entries(DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
211
262
|
|
|
212
263
|
// In case we don't have a translation for the locale, we fallback to the
|
|
213
|
-
// pattern
|
|
264
|
+
// Intl-derived pattern.
|
|
214
265
|
let pattern = localizedFormat;
|
|
215
266
|
if (localeMappings && localeMappings.length > 0) {
|
|
216
267
|
pattern = _reduceInstanceProperty(localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
@@ -225,6 +276,6 @@ const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
|
225
276
|
};
|
|
226
277
|
|
|
227
278
|
// NOTE: This string will be replaced on build time with the package version.
|
|
228
|
-
var version = "20.
|
|
279
|
+
var version = "20.3.1";
|
|
229
280
|
|
|
230
281
|
export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, formatDefaultTime, formatTime, getCalendarDayLabel, getDateInMonth, getDaysInMonth, getLocalizedDateTimeFormatPattern, getMonthCalendarLabel, getPaddingDayCount, getPreviousDay, getStartOf, getToday, getWeekdayNames, getYearCalendarLabel, isSameDay, parseInputText, version };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-uikit/calendar-time-utils",
|
|
3
3
|
"description": "Utilities to work with time values for a calendar.",
|
|
4
|
-
"version": "20.
|
|
4
|
+
"version": "20.3.1",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/runtime": "^7.20.13",
|
|
23
23
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
24
|
-
"@commercetools-uikit/utils": "20.
|
|
24
|
+
"@commercetools-uikit/utils": "20.3.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"moment-timezone": "0.6.0"
|