@commercetools-uikit/calendar-time-utils 15.0.0 → 15.0.2
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/commercetools-uikit-calendar-time-utils.cjs.dev.js +115 -1
- package/dist/commercetools-uikit-calendar-time-utils.cjs.prod.js +115 -1
- package/dist/commercetools-uikit-calendar-time-utils.esm.js +112 -2
- package/dist/declarations/src/calendar-time.d.ts +1 -0
- package/dist/declarations/src/formats.d.ts +23 -0
- package/package.json +1 -1
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
6
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
6
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 _Map = require('@babel/runtime-corejs3/core-js-stable/map');
|
|
13
|
+
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
14
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
11
15
|
var moment = require('moment-timezone');
|
|
12
16
|
var utils = require('@commercetools-uikit/utils');
|
|
17
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
18
|
|
|
14
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
15
20
|
|
|
@@ -18,8 +23,56 @@ var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanc
|
|
|
18
23
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
19
24
|
var _Array$from__default = /*#__PURE__*/_interopDefault(_Array$from);
|
|
20
25
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
26
|
+
var _Map__default = /*#__PURE__*/_interopDefault(_Map);
|
|
27
|
+
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
28
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
21
29
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
22
30
|
|
|
31
|
+
var _en, _de, _es, _fr, _ja, _zhCN;
|
|
32
|
+
|
|
33
|
+
// Reference: https://momentjs.com/docs/#/displaying/format/
|
|
34
|
+
var formatToken = {
|
|
35
|
+
D: 'D',
|
|
36
|
+
// NUMERIC_SINGLE_DAY
|
|
37
|
+
DD: 'DD',
|
|
38
|
+
// NUMERIC_TWO_DIGITS_DAY
|
|
39
|
+
M: 'M',
|
|
40
|
+
// NUMERIC_SINGLE_MONTH
|
|
41
|
+
MM: 'MM',
|
|
42
|
+
// NUMERIC_TWO_DIGIT_MONTH
|
|
43
|
+
YY: 'YY',
|
|
44
|
+
// TWO_DIGITS_YEAR
|
|
45
|
+
YYYY: 'YYYY',
|
|
46
|
+
// FOUR_DIGITS_YEAR
|
|
47
|
+
h: 'h',
|
|
48
|
+
// HOUR_12_SINGLE
|
|
49
|
+
hh: 'hh',
|
|
50
|
+
// HOUR_12_TWO_DIGITS
|
|
51
|
+
H: 'H',
|
|
52
|
+
// HOUR_24_SINGLE
|
|
53
|
+
HH: 'HH',
|
|
54
|
+
// HOUR_24_TWO_DIGITS
|
|
55
|
+
m: 'm',
|
|
56
|
+
// MINUTE_SINGLE
|
|
57
|
+
mm: 'mm',
|
|
58
|
+
// MINUTE_TWO_DIGITS
|
|
59
|
+
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
// Here is where we translate from the standard characters used in the pattern
|
|
63
|
+
// (calculated in the moment.js library) to the characters used in the locale
|
|
64
|
+
// We just need to provide the translation for the characters that are different
|
|
65
|
+
// For instance, in english we don't need to translate date characters as
|
|
66
|
+
// they are the same as the pattern characters
|
|
67
|
+
var DATE_FORMAT_LOCALIZED_MAPPINGS = {
|
|
68
|
+
en: (_en = {}, _defineProperty(_en, formatToken.h, 'HH'), _defineProperty(_en, formatToken.A, 'AM/PM'), _en),
|
|
69
|
+
de: (_de = {}, _defineProperty(_de, formatToken.DD, 'TT'), _defineProperty(_de, formatToken.YYYY, 'JJJJ'), _defineProperty(_de, formatToken.HH, 'SS'), _de),
|
|
70
|
+
es: (_es = {}, _defineProperty(_es, formatToken.H, 'HH'), _defineProperty(_es, formatToken.YYYY, 'AAAA'), _es),
|
|
71
|
+
fr: (_fr = {}, _defineProperty(_fr, formatToken.DD, 'JJ'), _defineProperty(_fr, formatToken.YYYY, 'AAAA'), _fr),
|
|
72
|
+
ja: (_ja = {}, _defineProperty(_ja, formatToken.HH, '午前/午後 時'), _defineProperty(_ja, formatToken.mm, '分'), _defineProperty(_ja, formatToken.DD, '日'), _defineProperty(_ja, formatToken.MM, '月'), _defineProperty(_ja, formatToken.YYYY, '年'), _ja),
|
|
73
|
+
'zh-CN': (_zhCN = {}, _defineProperty(_zhCN, formatToken.HH, '小时'), _defineProperty(_zhCN, formatToken.mm, '分钟'), _defineProperty(_zhCN, formatToken.DD, '日'), _defineProperty(_zhCN, formatToken.MM, '月'), _defineProperty(_zhCN, formatToken.YYYY, '年'), _zhCN)
|
|
74
|
+
};
|
|
75
|
+
|
|
23
76
|
var getDaysInMonth = function getDaysInMonth(day, timeZone) {
|
|
24
77
|
return moment__default["default"].tz(day, timeZone).daysInMonth();
|
|
25
78
|
};
|
|
@@ -139,9 +192,69 @@ var parseInputText = function parseInputText(text, locale, timeZone) {
|
|
|
139
192
|
|
|
140
193
|
return '';
|
|
141
194
|
};
|
|
195
|
+
var localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
196
|
+
var getLocalizedDateTimeFormatPattern = function getLocalizedDateTimeFormatPattern(locale) {
|
|
197
|
+
var _context4, _context5;
|
|
198
|
+
|
|
199
|
+
var formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
200
|
+
|
|
201
|
+
var key = _concatInstanceProperty__default["default"](_context4 = "".concat(locale, "::")).call(_context4, formatType);
|
|
202
|
+
|
|
203
|
+
if (localizedDateFormatPatternCache.has(key)) {
|
|
204
|
+
return localizedDateFormatPatternCache.get(key);
|
|
205
|
+
} // References:
|
|
206
|
+
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
207
|
+
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
var localeData = moment__default["default"]().locale(locale).localeData();
|
|
211
|
+
var localizedFormat = '';
|
|
212
|
+
|
|
213
|
+
switch (formatType) {
|
|
214
|
+
case 'date':
|
|
215
|
+
localizedFormat = localeData.longDateFormat('L');
|
|
216
|
+
break;
|
|
217
|
+
|
|
218
|
+
case 'time':
|
|
219
|
+
localizedFormat = localeData.longDateFormat('LT');
|
|
220
|
+
break;
|
|
221
|
+
|
|
222
|
+
case 'full':
|
|
223
|
+
localizedFormat = _concatInstanceProperty__default["default"](_context5 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context5, localeData.longDateFormat('LT'));
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
default:
|
|
227
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
228
|
+
} // We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
229
|
+
// and the generic language code (e.g. 'en').
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
var _locale$split = locale.split('-'),
|
|
233
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
234
|
+
languageCode = _locale$split2[0];
|
|
235
|
+
|
|
236
|
+
var localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {}); // In case we don't have a translation for the locale, we fallback to the
|
|
237
|
+
// pattern from the moment locale data.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
var pattern = localizedFormat;
|
|
241
|
+
|
|
242
|
+
if (localeMappings && localeMappings.length > 0) {
|
|
243
|
+
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, function (localizedPattern, _ref) {
|
|
244
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
245
|
+
token = _ref2[0],
|
|
246
|
+
mappedValue = _ref2[1];
|
|
247
|
+
|
|
248
|
+
return localizedPattern.replace(token, mappedValue);
|
|
249
|
+
}, localizedFormat);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
localizedDateFormatPatternCache.set(key, pattern);
|
|
253
|
+
return pattern;
|
|
254
|
+
};
|
|
142
255
|
|
|
143
256
|
// NOTE: This string will be replaced on build time with the package version.
|
|
144
|
-
var version = "15.0.
|
|
257
|
+
var version = "15.0.2";
|
|
145
258
|
|
|
146
259
|
exports.changeDateInMonth = changeDateInMonth;
|
|
147
260
|
exports.changeMonth = changeMonth;
|
|
@@ -154,6 +267,7 @@ exports.formatTime = formatTime;
|
|
|
154
267
|
exports.getCalendarDayLabel = getCalendarDayLabel;
|
|
155
268
|
exports.getDateInMonth = getDateInMonth;
|
|
156
269
|
exports.getDaysInMonth = getDaysInMonth;
|
|
270
|
+
exports.getLocalizedDateTimeFormatPattern = getLocalizedDateTimeFormatPattern;
|
|
157
271
|
exports.getMonthCalendarLabel = getMonthCalendarLabel;
|
|
158
272
|
exports.getPaddingDayCount = getPaddingDayCount;
|
|
159
273
|
exports.getPreviousDay = getPreviousDay;
|
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
6
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
6
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 _Map = require('@babel/runtime-corejs3/core-js-stable/map');
|
|
13
|
+
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
14
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
11
15
|
var moment = require('moment-timezone');
|
|
12
16
|
var utils = require('@commercetools-uikit/utils');
|
|
17
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
13
18
|
|
|
14
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
15
20
|
|
|
@@ -18,8 +23,56 @@ var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanc
|
|
|
18
23
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
19
24
|
var _Array$from__default = /*#__PURE__*/_interopDefault(_Array$from);
|
|
20
25
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
26
|
+
var _Map__default = /*#__PURE__*/_interopDefault(_Map);
|
|
27
|
+
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
28
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
21
29
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
22
30
|
|
|
31
|
+
var _en, _de, _es, _fr, _ja, _zhCN;
|
|
32
|
+
|
|
33
|
+
// Reference: https://momentjs.com/docs/#/displaying/format/
|
|
34
|
+
var formatToken = {
|
|
35
|
+
D: 'D',
|
|
36
|
+
// NUMERIC_SINGLE_DAY
|
|
37
|
+
DD: 'DD',
|
|
38
|
+
// NUMERIC_TWO_DIGITS_DAY
|
|
39
|
+
M: 'M',
|
|
40
|
+
// NUMERIC_SINGLE_MONTH
|
|
41
|
+
MM: 'MM',
|
|
42
|
+
// NUMERIC_TWO_DIGIT_MONTH
|
|
43
|
+
YY: 'YY',
|
|
44
|
+
// TWO_DIGITS_YEAR
|
|
45
|
+
YYYY: 'YYYY',
|
|
46
|
+
// FOUR_DIGITS_YEAR
|
|
47
|
+
h: 'h',
|
|
48
|
+
// HOUR_12_SINGLE
|
|
49
|
+
hh: 'hh',
|
|
50
|
+
// HOUR_12_TWO_DIGITS
|
|
51
|
+
H: 'H',
|
|
52
|
+
// HOUR_24_SINGLE
|
|
53
|
+
HH: 'HH',
|
|
54
|
+
// HOUR_24_TWO_DIGITS
|
|
55
|
+
m: 'm',
|
|
56
|
+
// MINUTE_SINGLE
|
|
57
|
+
mm: 'mm',
|
|
58
|
+
// MINUTE_TWO_DIGITS
|
|
59
|
+
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
// Here is where we translate from the standard characters used in the pattern
|
|
63
|
+
// (calculated in the moment.js library) to the characters used in the locale
|
|
64
|
+
// We just need to provide the translation for the characters that are different
|
|
65
|
+
// For instance, in english we don't need to translate date characters as
|
|
66
|
+
// they are the same as the pattern characters
|
|
67
|
+
var DATE_FORMAT_LOCALIZED_MAPPINGS = {
|
|
68
|
+
en: (_en = {}, _defineProperty(_en, formatToken.h, 'HH'), _defineProperty(_en, formatToken.A, 'AM/PM'), _en),
|
|
69
|
+
de: (_de = {}, _defineProperty(_de, formatToken.DD, 'TT'), _defineProperty(_de, formatToken.YYYY, 'JJJJ'), _defineProperty(_de, formatToken.HH, 'SS'), _de),
|
|
70
|
+
es: (_es = {}, _defineProperty(_es, formatToken.H, 'HH'), _defineProperty(_es, formatToken.YYYY, 'AAAA'), _es),
|
|
71
|
+
fr: (_fr = {}, _defineProperty(_fr, formatToken.DD, 'JJ'), _defineProperty(_fr, formatToken.YYYY, 'AAAA'), _fr),
|
|
72
|
+
ja: (_ja = {}, _defineProperty(_ja, formatToken.HH, '午前/午後 時'), _defineProperty(_ja, formatToken.mm, '分'), _defineProperty(_ja, formatToken.DD, '日'), _defineProperty(_ja, formatToken.MM, '月'), _defineProperty(_ja, formatToken.YYYY, '年'), _ja),
|
|
73
|
+
'zh-CN': (_zhCN = {}, _defineProperty(_zhCN, formatToken.HH, '小时'), _defineProperty(_zhCN, formatToken.mm, '分钟'), _defineProperty(_zhCN, formatToken.DD, '日'), _defineProperty(_zhCN, formatToken.MM, '月'), _defineProperty(_zhCN, formatToken.YYYY, '年'), _zhCN)
|
|
74
|
+
};
|
|
75
|
+
|
|
23
76
|
var getDaysInMonth = function getDaysInMonth(day, timeZone) {
|
|
24
77
|
return moment__default["default"].tz(day, timeZone).daysInMonth();
|
|
25
78
|
};
|
|
@@ -139,9 +192,69 @@ var parseInputText = function parseInputText(text, locale, timeZone) {
|
|
|
139
192
|
|
|
140
193
|
return '';
|
|
141
194
|
};
|
|
195
|
+
var localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
196
|
+
var getLocalizedDateTimeFormatPattern = function getLocalizedDateTimeFormatPattern(locale) {
|
|
197
|
+
var _context4, _context5;
|
|
198
|
+
|
|
199
|
+
var formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
200
|
+
|
|
201
|
+
var key = _concatInstanceProperty__default["default"](_context4 = "".concat(locale, "::")).call(_context4, formatType);
|
|
202
|
+
|
|
203
|
+
if (localizedDateFormatPatternCache.has(key)) {
|
|
204
|
+
return localizedDateFormatPatternCache.get(key);
|
|
205
|
+
} // References:
|
|
206
|
+
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
207
|
+
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
var localeData = moment__default["default"]().locale(locale).localeData();
|
|
211
|
+
var localizedFormat = '';
|
|
212
|
+
|
|
213
|
+
switch (formatType) {
|
|
214
|
+
case 'date':
|
|
215
|
+
localizedFormat = localeData.longDateFormat('L');
|
|
216
|
+
break;
|
|
217
|
+
|
|
218
|
+
case 'time':
|
|
219
|
+
localizedFormat = localeData.longDateFormat('LT');
|
|
220
|
+
break;
|
|
221
|
+
|
|
222
|
+
case 'full':
|
|
223
|
+
localizedFormat = _concatInstanceProperty__default["default"](_context5 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context5, localeData.longDateFormat('LT'));
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
default:
|
|
227
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
228
|
+
} // We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
229
|
+
// and the generic language code (e.g. 'en').
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
var _locale$split = locale.split('-'),
|
|
233
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
234
|
+
languageCode = _locale$split2[0];
|
|
235
|
+
|
|
236
|
+
var localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {}); // In case we don't have a translation for the locale, we fallback to the
|
|
237
|
+
// pattern from the moment locale data.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
var pattern = localizedFormat;
|
|
241
|
+
|
|
242
|
+
if (localeMappings && localeMappings.length > 0) {
|
|
243
|
+
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, function (localizedPattern, _ref) {
|
|
244
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
245
|
+
token = _ref2[0],
|
|
246
|
+
mappedValue = _ref2[1];
|
|
247
|
+
|
|
248
|
+
return localizedPattern.replace(token, mappedValue);
|
|
249
|
+
}, localizedFormat);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
localizedDateFormatPatternCache.set(key, pattern);
|
|
253
|
+
return pattern;
|
|
254
|
+
};
|
|
142
255
|
|
|
143
256
|
// NOTE: This string will be replaced on build time with the package version.
|
|
144
|
-
var version = "15.0.
|
|
257
|
+
var version = "15.0.2";
|
|
145
258
|
|
|
146
259
|
exports.changeDateInMonth = changeDateInMonth;
|
|
147
260
|
exports.changeMonth = changeMonth;
|
|
@@ -154,6 +267,7 @@ exports.formatTime = formatTime;
|
|
|
154
267
|
exports.getCalendarDayLabel = getCalendarDayLabel;
|
|
155
268
|
exports.getDateInMonth = getDateInMonth;
|
|
156
269
|
exports.getDaysInMonth = getDaysInMonth;
|
|
270
|
+
exports.getLocalizedDateTimeFormatPattern = getLocalizedDateTimeFormatPattern;
|
|
157
271
|
exports.getMonthCalendarLabel = getMonthCalendarLabel;
|
|
158
272
|
exports.getPaddingDayCount = getPaddingDayCount;
|
|
159
273
|
exports.getPreviousDay = getPreviousDay;
|
|
@@ -1,11 +1,61 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
1
2
|
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
2
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 _Map from '@babel/runtime-corejs3/core-js-stable/map';
|
|
9
|
+
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
10
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
7
11
|
import moment from 'moment-timezone';
|
|
8
12
|
import { parseTime } from '@commercetools-uikit/utils';
|
|
13
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
14
|
+
|
|
15
|
+
var _en, _de, _es, _fr, _ja, _zhCN;
|
|
16
|
+
|
|
17
|
+
// Reference: https://momentjs.com/docs/#/displaying/format/
|
|
18
|
+
var formatToken = {
|
|
19
|
+
D: 'D',
|
|
20
|
+
// NUMERIC_SINGLE_DAY
|
|
21
|
+
DD: 'DD',
|
|
22
|
+
// NUMERIC_TWO_DIGITS_DAY
|
|
23
|
+
M: 'M',
|
|
24
|
+
// NUMERIC_SINGLE_MONTH
|
|
25
|
+
MM: 'MM',
|
|
26
|
+
// NUMERIC_TWO_DIGIT_MONTH
|
|
27
|
+
YY: 'YY',
|
|
28
|
+
// TWO_DIGITS_YEAR
|
|
29
|
+
YYYY: 'YYYY',
|
|
30
|
+
// FOUR_DIGITS_YEAR
|
|
31
|
+
h: 'h',
|
|
32
|
+
// HOUR_12_SINGLE
|
|
33
|
+
hh: 'hh',
|
|
34
|
+
// HOUR_12_TWO_DIGITS
|
|
35
|
+
H: 'H',
|
|
36
|
+
// HOUR_24_SINGLE
|
|
37
|
+
HH: 'HH',
|
|
38
|
+
// HOUR_24_TWO_DIGITS
|
|
39
|
+
m: 'm',
|
|
40
|
+
// MINUTE_SINGLE
|
|
41
|
+
mm: 'mm',
|
|
42
|
+
// MINUTE_TWO_DIGITS
|
|
43
|
+
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
// Here is where we translate from the standard characters used in the pattern
|
|
47
|
+
// (calculated in the moment.js library) to the characters used in the locale
|
|
48
|
+
// We just need to provide the translation for the characters that are different
|
|
49
|
+
// For instance, in english we don't need to translate date characters as
|
|
50
|
+
// they are the same as the pattern characters
|
|
51
|
+
var DATE_FORMAT_LOCALIZED_MAPPINGS = {
|
|
52
|
+
en: (_en = {}, _defineProperty(_en, formatToken.h, 'HH'), _defineProperty(_en, formatToken.A, 'AM/PM'), _en),
|
|
53
|
+
de: (_de = {}, _defineProperty(_de, formatToken.DD, 'TT'), _defineProperty(_de, formatToken.YYYY, 'JJJJ'), _defineProperty(_de, formatToken.HH, 'SS'), _de),
|
|
54
|
+
es: (_es = {}, _defineProperty(_es, formatToken.H, 'HH'), _defineProperty(_es, formatToken.YYYY, 'AAAA'), _es),
|
|
55
|
+
fr: (_fr = {}, _defineProperty(_fr, formatToken.DD, 'JJ'), _defineProperty(_fr, formatToken.YYYY, 'AAAA'), _fr),
|
|
56
|
+
ja: (_ja = {}, _defineProperty(_ja, formatToken.HH, '午前/午後 時'), _defineProperty(_ja, formatToken.mm, '分'), _defineProperty(_ja, formatToken.DD, '日'), _defineProperty(_ja, formatToken.MM, '月'), _defineProperty(_ja, formatToken.YYYY, '年'), _ja),
|
|
57
|
+
'zh-CN': (_zhCN = {}, _defineProperty(_zhCN, formatToken.HH, '小时'), _defineProperty(_zhCN, formatToken.mm, '分钟'), _defineProperty(_zhCN, formatToken.DD, '日'), _defineProperty(_zhCN, formatToken.MM, '月'), _defineProperty(_zhCN, formatToken.YYYY, '年'), _zhCN)
|
|
58
|
+
};
|
|
9
59
|
|
|
10
60
|
var getDaysInMonth = function getDaysInMonth(day, timeZone) {
|
|
11
61
|
return moment.tz(day, timeZone).daysInMonth();
|
|
@@ -126,8 +176,68 @@ var parseInputText = function parseInputText(text, locale, timeZone) {
|
|
|
126
176
|
|
|
127
177
|
return '';
|
|
128
178
|
};
|
|
179
|
+
var localizedDateFormatPatternCache = new _Map();
|
|
180
|
+
var getLocalizedDateTimeFormatPattern = function getLocalizedDateTimeFormatPattern(locale) {
|
|
181
|
+
var _context4, _context5;
|
|
182
|
+
|
|
183
|
+
var formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
184
|
+
|
|
185
|
+
var key = _concatInstanceProperty(_context4 = "".concat(locale, "::")).call(_context4, formatType);
|
|
186
|
+
|
|
187
|
+
if (localizedDateFormatPatternCache.has(key)) {
|
|
188
|
+
return localizedDateFormatPatternCache.get(key);
|
|
189
|
+
} // References:
|
|
190
|
+
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
191
|
+
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
var localeData = moment().locale(locale).localeData();
|
|
195
|
+
var localizedFormat = '';
|
|
196
|
+
|
|
197
|
+
switch (formatType) {
|
|
198
|
+
case 'date':
|
|
199
|
+
localizedFormat = localeData.longDateFormat('L');
|
|
200
|
+
break;
|
|
201
|
+
|
|
202
|
+
case 'time':
|
|
203
|
+
localizedFormat = localeData.longDateFormat('LT');
|
|
204
|
+
break;
|
|
205
|
+
|
|
206
|
+
case 'full':
|
|
207
|
+
localizedFormat = _concatInstanceProperty(_context5 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context5, localeData.longDateFormat('LT'));
|
|
208
|
+
break;
|
|
209
|
+
|
|
210
|
+
default:
|
|
211
|
+
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
212
|
+
} // We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
213
|
+
// and the generic language code (e.g. 'en').
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
var _locale$split = locale.split('-'),
|
|
217
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
218
|
+
languageCode = _locale$split2[0];
|
|
219
|
+
|
|
220
|
+
var localeMappings = _Object$entries(DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {}); // In case we don't have a translation for the locale, we fallback to the
|
|
221
|
+
// pattern from the moment locale data.
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
var pattern = localizedFormat;
|
|
225
|
+
|
|
226
|
+
if (localeMappings && localeMappings.length > 0) {
|
|
227
|
+
pattern = _reduceInstanceProperty(localeMappings).call(localeMappings, function (localizedPattern, _ref) {
|
|
228
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
229
|
+
token = _ref2[0],
|
|
230
|
+
mappedValue = _ref2[1];
|
|
231
|
+
|
|
232
|
+
return localizedPattern.replace(token, mappedValue);
|
|
233
|
+
}, localizedFormat);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
localizedDateFormatPatternCache.set(key, pattern);
|
|
237
|
+
return pattern;
|
|
238
|
+
};
|
|
129
239
|
|
|
130
240
|
// NOTE: This string will be replaced on build time with the package version.
|
|
131
|
-
var version = "15.0.
|
|
241
|
+
var version = "15.0.2";
|
|
132
242
|
|
|
133
|
-
export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, formatTime, getCalendarDayLabel, getDateInMonth, getDaysInMonth, getMonthCalendarLabel, getPaddingDayCount, getPreviousDay, getStartOf, getToday, getWeekdayNames, getYearCalendarLabel, isSameDay, parseInputText, version };
|
|
243
|
+
export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, formatTime, getCalendarDayLabel, getDateInMonth, getDaysInMonth, getLocalizedDateTimeFormatPattern, getMonthCalendarLabel, getPaddingDayCount, getPreviousDay, getStartOf, getToday, getWeekdayNames, getYearCalendarLabel, isSameDay, parseInputText, version };
|
|
@@ -25,4 +25,5 @@ export declare const createItemDateTimeToString: (locale: string, timeZone: stri
|
|
|
25
25
|
export declare const createCalendarItems: (day: MomentInput, timeString: string, timeZone: string) => string[];
|
|
26
26
|
export declare const createSuggestedItems: (inputValue: string, timeZone: string) => string[];
|
|
27
27
|
export declare const parseInputText: (text: string, locale: string, timeZone: string) => string;
|
|
28
|
+
export declare const getLocalizedDateTimeFormatPattern: (locale: string, formatType?: 'date' | 'time' | 'full') => string;
|
|
28
29
|
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare const formatToken: {
|
|
2
|
+
readonly D: "D";
|
|
3
|
+
readonly DD: "DD";
|
|
4
|
+
readonly M: "M";
|
|
5
|
+
readonly MM: "MM";
|
|
6
|
+
readonly YY: "YY";
|
|
7
|
+
readonly YYYY: "YYYY";
|
|
8
|
+
readonly h: "h";
|
|
9
|
+
readonly hh: "hh";
|
|
10
|
+
readonly H: "H";
|
|
11
|
+
readonly HH: "HH";
|
|
12
|
+
readonly m: "m";
|
|
13
|
+
readonly mm: "mm";
|
|
14
|
+
readonly A: "A";
|
|
15
|
+
};
|
|
16
|
+
export declare type TLocaleDateFormatMapping = {
|
|
17
|
+
[key in keyof typeof formatToken]?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare type TLocalizedDateFormatMapping = {
|
|
20
|
+
[locale: string]: TLocaleDateFormatMapping;
|
|
21
|
+
};
|
|
22
|
+
export declare const DATE_FORMAT_LOCALIZED_MAPPINGS: TLocalizedDateFormatMapping;
|
|
23
|
+
export {};
|
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": "15.0.
|
|
4
|
+
"version": "15.0.2",
|
|
5
5
|
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|