@commercetools-uikit/calendar-time-utils 16.0.0 → 16.1.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.
|
@@ -53,8 +53,8 @@ const formatToken = {
|
|
|
53
53
|
mm: 'mm',
|
|
54
54
|
// MINUTE_TWO_DIGITS
|
|
55
55
|
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
56
|
-
|
|
57
56
|
};
|
|
57
|
+
|
|
58
58
|
// Here is where we translate from the standard characters used in the pattern
|
|
59
59
|
// (calculated in the moment.js library) to the characters used in the locale
|
|
60
60
|
// We just need to provide the translation for the characters that are different
|
|
@@ -108,12 +108,11 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
108
108
|
const date = moment__default["default"].tz(day, timeZone).locale(locale);
|
|
109
109
|
if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
|
|
110
110
|
if (date.seconds()) return date.format('LTS'); // 5:13:51 PM
|
|
111
|
-
|
|
112
111
|
return date.format('LT'); // 5:13 PM
|
|
113
112
|
};
|
|
113
|
+
|
|
114
114
|
const formatDate = (day, locale, timeZone) => {
|
|
115
115
|
var _context;
|
|
116
|
-
|
|
117
116
|
const date = moment__default["default"](day, moment__default["default"].ISO_8601, locale).tz(timeZone).format('L');
|
|
118
117
|
const time = formatTime(day, locale, timeZone);
|
|
119
118
|
return _concatInstanceProperty__default["default"](_context = "".concat(date, " ")).call(_context, time);
|
|
@@ -123,8 +122,9 @@ const getToday = timeZone => moment__default["default"].tz(timeZone).startOf('da
|
|
|
123
122
|
const changeMonth = (day, timeZone, delta) => moment__default["default"].tz(day, timeZone).add(delta, 'month').toISOString();
|
|
124
123
|
const getPaddingDayCount = (day, locale, timeZone) => {
|
|
125
124
|
const firstDayOfWeek = moment__default["default"].localeData(locale).firstDayOfWeek();
|
|
126
|
-
const firstDayOfMonth = moment__default["default"].tz(day, timeZone).startOf('month').day();
|
|
125
|
+
const firstDayOfMonth = moment__default["default"].tz(day, timeZone).startOf('month').day();
|
|
127
126
|
|
|
127
|
+
// ensure number is always positive
|
|
128
128
|
return (firstDayOfMonth - firstDayOfWeek + 7) % 7;
|
|
129
129
|
};
|
|
130
130
|
const getWeekdayNames = locale => {
|
|
@@ -140,18 +140,15 @@ const getCalendarDayLabel = (day, timeZone) => moment__default["default"].tz(day
|
|
|
140
140
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
141
141
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
142
142
|
var _context2;
|
|
143
|
-
|
|
144
143
|
const parsedTime = utils.parseTime(timeString);
|
|
145
144
|
return _mapInstanceProperty__default["default"](_context2 = _Array$from__default["default"]({
|
|
146
145
|
length: getDaysInMonth(day, timeZone)
|
|
147
146
|
})).call(_context2, (_, i) => {
|
|
148
147
|
const dayOfMonth = i + 1;
|
|
149
148
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
150
|
-
|
|
151
149
|
if (parsedTime) {
|
|
152
150
|
date = changeTime(date, timeZone, parsedTime);
|
|
153
151
|
}
|
|
154
|
-
|
|
155
152
|
return date;
|
|
156
153
|
});
|
|
157
154
|
};
|
|
@@ -162,16 +159,14 @@ const createSuggestedItems = (inputValue, timeZone) => {
|
|
|
162
159
|
const parseInputText = (text, locale, timeZone) => {
|
|
163
160
|
const parts = text.split(' ');
|
|
164
161
|
const dateString = parts[0];
|
|
165
|
-
|
|
166
162
|
const timeString = _sliceInstanceProperty__default["default"](parts).call(parts, 1).join(' ');
|
|
167
|
-
|
|
168
163
|
if (!dateString) return '';
|
|
169
164
|
const date = moment__default["default"].tz(dateString, moment__default["default"].localeData(locale).longDateFormat('L'), timeZone);
|
|
170
|
-
if (!date.isValid()) return '';
|
|
165
|
+
if (!date.isValid()) return '';
|
|
171
166
|
|
|
167
|
+
// enable parsing a date only
|
|
172
168
|
if (!timeString) return date.startOf('day').toISOString();
|
|
173
169
|
const parsedTime = utils.parseTime(timeString);
|
|
174
|
-
|
|
175
170
|
if (parsedTime) {
|
|
176
171
|
date.hours(parsedTime.hours);
|
|
177
172
|
date.minutes(parsedTime.minutes);
|
|
@@ -180,72 +175,60 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
180
175
|
date.milliseconds(parsedTime.milliseconds);
|
|
181
176
|
return date.toISOString();
|
|
182
177
|
}
|
|
183
|
-
|
|
184
178
|
return '';
|
|
185
179
|
};
|
|
186
180
|
const localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
187
181
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
188
182
|
var _context3, _context4;
|
|
189
|
-
|
|
190
183
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
191
|
-
|
|
192
184
|
const key = _concatInstanceProperty__default["default"](_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
193
|
-
|
|
194
185
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
195
186
|
return localizedDateFormatPatternCache.get(key);
|
|
196
|
-
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// References:
|
|
197
190
|
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
198
191
|
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
199
|
-
|
|
200
|
-
|
|
201
192
|
const localeData = moment__default["default"]().locale(locale).localeData();
|
|
202
193
|
let localizedFormat = '';
|
|
203
|
-
|
|
204
194
|
switch (formatType) {
|
|
205
195
|
case 'date':
|
|
206
196
|
localizedFormat = localeData.longDateFormat('L');
|
|
207
197
|
break;
|
|
208
|
-
|
|
209
198
|
case 'time':
|
|
210
199
|
localizedFormat = localeData.longDateFormat('LT');
|
|
211
200
|
break;
|
|
212
|
-
|
|
213
201
|
case 'full':
|
|
214
202
|
localizedFormat = _concatInstanceProperty__default["default"](_context4 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context4, localeData.longDateFormat('LT'));
|
|
215
203
|
break;
|
|
216
|
-
|
|
217
204
|
default:
|
|
218
205
|
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
219
|
-
}
|
|
220
|
-
// and the generic language code (e.g. 'en').
|
|
221
|
-
|
|
206
|
+
}
|
|
222
207
|
|
|
208
|
+
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
209
|
+
// and the generic language code (e.g. 'en').
|
|
223
210
|
const _locale$split = locale.split('-'),
|
|
224
|
-
|
|
225
|
-
|
|
211
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
212
|
+
languageCode = _locale$split2[0];
|
|
213
|
+
const localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
226
214
|
|
|
227
|
-
|
|
215
|
+
// In case we don't have a translation for the locale, we fallback to the
|
|
228
216
|
// pattern from the moment locale data.
|
|
229
|
-
|
|
230
|
-
|
|
231
217
|
let pattern = localizedFormat;
|
|
232
|
-
|
|
233
218
|
if (localeMappings && localeMappings.length > 0) {
|
|
234
219
|
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
235
220
|
let _ref2 = _slicedToArray(_ref, 2),
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
221
|
+
token = _ref2[0],
|
|
222
|
+
mappedValue = _ref2[1];
|
|
239
223
|
return localizedPattern.replace(token, mappedValue);
|
|
240
224
|
}, localizedFormat);
|
|
241
225
|
}
|
|
242
|
-
|
|
243
226
|
localizedDateFormatPatternCache.set(key, pattern);
|
|
244
227
|
return pattern;
|
|
245
228
|
};
|
|
246
229
|
|
|
247
230
|
// NOTE: This string will be replaced on build time with the package version.
|
|
248
|
-
var version = "16.
|
|
231
|
+
var version = "16.1.1";
|
|
249
232
|
|
|
250
233
|
exports.changeDateInMonth = changeDateInMonth;
|
|
251
234
|
exports.changeMonth = changeMonth;
|
|
@@ -53,8 +53,8 @@ const formatToken = {
|
|
|
53
53
|
mm: 'mm',
|
|
54
54
|
// MINUTE_TWO_DIGITS
|
|
55
55
|
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
56
|
-
|
|
57
56
|
};
|
|
57
|
+
|
|
58
58
|
// Here is where we translate from the standard characters used in the pattern
|
|
59
59
|
// (calculated in the moment.js library) to the characters used in the locale
|
|
60
60
|
// We just need to provide the translation for the characters that are different
|
|
@@ -108,12 +108,11 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
108
108
|
const date = moment__default["default"].tz(day, timeZone).locale(locale);
|
|
109
109
|
if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
|
|
110
110
|
if (date.seconds()) return date.format('LTS'); // 5:13:51 PM
|
|
111
|
-
|
|
112
111
|
return date.format('LT'); // 5:13 PM
|
|
113
112
|
};
|
|
113
|
+
|
|
114
114
|
const formatDate = (day, locale, timeZone) => {
|
|
115
115
|
var _context;
|
|
116
|
-
|
|
117
116
|
const date = moment__default["default"](day, moment__default["default"].ISO_8601, locale).tz(timeZone).format('L');
|
|
118
117
|
const time = formatTime(day, locale, timeZone);
|
|
119
118
|
return _concatInstanceProperty__default["default"](_context = "".concat(date, " ")).call(_context, time);
|
|
@@ -123,8 +122,9 @@ const getToday = timeZone => moment__default["default"].tz(timeZone).startOf('da
|
|
|
123
122
|
const changeMonth = (day, timeZone, delta) => moment__default["default"].tz(day, timeZone).add(delta, 'month').toISOString();
|
|
124
123
|
const getPaddingDayCount = (day, locale, timeZone) => {
|
|
125
124
|
const firstDayOfWeek = moment__default["default"].localeData(locale).firstDayOfWeek();
|
|
126
|
-
const firstDayOfMonth = moment__default["default"].tz(day, timeZone).startOf('month').day();
|
|
125
|
+
const firstDayOfMonth = moment__default["default"].tz(day, timeZone).startOf('month').day();
|
|
127
126
|
|
|
127
|
+
// ensure number is always positive
|
|
128
128
|
return (firstDayOfMonth - firstDayOfWeek + 7) % 7;
|
|
129
129
|
};
|
|
130
130
|
const getWeekdayNames = locale => {
|
|
@@ -140,18 +140,15 @@ const getCalendarDayLabel = (day, timeZone) => moment__default["default"].tz(day
|
|
|
140
140
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
141
141
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
142
142
|
var _context2;
|
|
143
|
-
|
|
144
143
|
const parsedTime = utils.parseTime(timeString);
|
|
145
144
|
return _mapInstanceProperty__default["default"](_context2 = _Array$from__default["default"]({
|
|
146
145
|
length: getDaysInMonth(day, timeZone)
|
|
147
146
|
})).call(_context2, (_, i) => {
|
|
148
147
|
const dayOfMonth = i + 1;
|
|
149
148
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
150
|
-
|
|
151
149
|
if (parsedTime) {
|
|
152
150
|
date = changeTime(date, timeZone, parsedTime);
|
|
153
151
|
}
|
|
154
|
-
|
|
155
152
|
return date;
|
|
156
153
|
});
|
|
157
154
|
};
|
|
@@ -162,16 +159,14 @@ const createSuggestedItems = (inputValue, timeZone) => {
|
|
|
162
159
|
const parseInputText = (text, locale, timeZone) => {
|
|
163
160
|
const parts = text.split(' ');
|
|
164
161
|
const dateString = parts[0];
|
|
165
|
-
|
|
166
162
|
const timeString = _sliceInstanceProperty__default["default"](parts).call(parts, 1).join(' ');
|
|
167
|
-
|
|
168
163
|
if (!dateString) return '';
|
|
169
164
|
const date = moment__default["default"].tz(dateString, moment__default["default"].localeData(locale).longDateFormat('L'), timeZone);
|
|
170
|
-
if (!date.isValid()) return '';
|
|
165
|
+
if (!date.isValid()) return '';
|
|
171
166
|
|
|
167
|
+
// enable parsing a date only
|
|
172
168
|
if (!timeString) return date.startOf('day').toISOString();
|
|
173
169
|
const parsedTime = utils.parseTime(timeString);
|
|
174
|
-
|
|
175
170
|
if (parsedTime) {
|
|
176
171
|
date.hours(parsedTime.hours);
|
|
177
172
|
date.minutes(parsedTime.minutes);
|
|
@@ -180,72 +175,60 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
180
175
|
date.milliseconds(parsedTime.milliseconds);
|
|
181
176
|
return date.toISOString();
|
|
182
177
|
}
|
|
183
|
-
|
|
184
178
|
return '';
|
|
185
179
|
};
|
|
186
180
|
const localizedDateFormatPatternCache = new _Map__default["default"]();
|
|
187
181
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
188
182
|
var _context3, _context4;
|
|
189
|
-
|
|
190
183
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
191
|
-
|
|
192
184
|
const key = _concatInstanceProperty__default["default"](_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
193
|
-
|
|
194
185
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
195
186
|
return localizedDateFormatPatternCache.get(key);
|
|
196
|
-
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// References:
|
|
197
190
|
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
198
191
|
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
199
|
-
|
|
200
|
-
|
|
201
192
|
const localeData = moment__default["default"]().locale(locale).localeData();
|
|
202
193
|
let localizedFormat = '';
|
|
203
|
-
|
|
204
194
|
switch (formatType) {
|
|
205
195
|
case 'date':
|
|
206
196
|
localizedFormat = localeData.longDateFormat('L');
|
|
207
197
|
break;
|
|
208
|
-
|
|
209
198
|
case 'time':
|
|
210
199
|
localizedFormat = localeData.longDateFormat('LT');
|
|
211
200
|
break;
|
|
212
|
-
|
|
213
201
|
case 'full':
|
|
214
202
|
localizedFormat = _concatInstanceProperty__default["default"](_context4 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context4, localeData.longDateFormat('LT'));
|
|
215
203
|
break;
|
|
216
|
-
|
|
217
204
|
default:
|
|
218
205
|
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
219
|
-
}
|
|
220
|
-
// and the generic language code (e.g. 'en').
|
|
221
|
-
|
|
206
|
+
}
|
|
222
207
|
|
|
208
|
+
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
209
|
+
// and the generic language code (e.g. 'en').
|
|
223
210
|
const _locale$split = locale.split('-'),
|
|
224
|
-
|
|
225
|
-
|
|
211
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
212
|
+
languageCode = _locale$split2[0];
|
|
213
|
+
const localeMappings = _Object$entries__default["default"](DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
226
214
|
|
|
227
|
-
|
|
215
|
+
// In case we don't have a translation for the locale, we fallback to the
|
|
228
216
|
// pattern from the moment locale data.
|
|
229
|
-
|
|
230
|
-
|
|
231
217
|
let pattern = localizedFormat;
|
|
232
|
-
|
|
233
218
|
if (localeMappings && localeMappings.length > 0) {
|
|
234
219
|
pattern = _reduceInstanceProperty__default["default"](localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
235
220
|
let _ref2 = _slicedToArray(_ref, 2),
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
221
|
+
token = _ref2[0],
|
|
222
|
+
mappedValue = _ref2[1];
|
|
239
223
|
return localizedPattern.replace(token, mappedValue);
|
|
240
224
|
}, localizedFormat);
|
|
241
225
|
}
|
|
242
|
-
|
|
243
226
|
localizedDateFormatPatternCache.set(key, pattern);
|
|
244
227
|
return pattern;
|
|
245
228
|
};
|
|
246
229
|
|
|
247
230
|
// NOTE: This string will be replaced on build time with the package version.
|
|
248
|
-
var version = "16.
|
|
231
|
+
var version = "16.1.1";
|
|
249
232
|
|
|
250
233
|
exports.changeDateInMonth = changeDateInMonth;
|
|
251
234
|
exports.changeMonth = changeMonth;
|
|
@@ -37,8 +37,8 @@ const formatToken = {
|
|
|
37
37
|
mm: 'mm',
|
|
38
38
|
// MINUTE_TWO_DIGITS
|
|
39
39
|
A: 'A' // PERIOD - https://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
|
40
|
-
|
|
41
40
|
};
|
|
41
|
+
|
|
42
42
|
// Here is where we translate from the standard characters used in the pattern
|
|
43
43
|
// (calculated in the moment.js library) to the characters used in the locale
|
|
44
44
|
// We just need to provide the translation for the characters that are different
|
|
@@ -92,12 +92,11 @@ const formatTime = (day, locale, timeZone) => {
|
|
|
92
92
|
const date = moment.tz(day, timeZone).locale(locale);
|
|
93
93
|
if (date.milliseconds()) return date.format('HH:mm:ss.SSS');
|
|
94
94
|
if (date.seconds()) return date.format('LTS'); // 5:13:51 PM
|
|
95
|
-
|
|
96
95
|
return date.format('LT'); // 5:13 PM
|
|
97
96
|
};
|
|
97
|
+
|
|
98
98
|
const formatDate = (day, locale, timeZone) => {
|
|
99
99
|
var _context;
|
|
100
|
-
|
|
101
100
|
const date = moment(day, moment.ISO_8601, locale).tz(timeZone).format('L');
|
|
102
101
|
const time = formatTime(day, locale, timeZone);
|
|
103
102
|
return _concatInstanceProperty(_context = "".concat(date, " ")).call(_context, time);
|
|
@@ -107,8 +106,9 @@ const getToday = timeZone => moment.tz(timeZone).startOf('day').toISOString();
|
|
|
107
106
|
const changeMonth = (day, timeZone, delta) => moment.tz(day, timeZone).add(delta, 'month').toISOString();
|
|
108
107
|
const getPaddingDayCount = (day, locale, timeZone) => {
|
|
109
108
|
const firstDayOfWeek = moment.localeData(locale).firstDayOfWeek();
|
|
110
|
-
const firstDayOfMonth = moment.tz(day, timeZone).startOf('month').day();
|
|
109
|
+
const firstDayOfMonth = moment.tz(day, timeZone).startOf('month').day();
|
|
111
110
|
|
|
111
|
+
// ensure number is always positive
|
|
112
112
|
return (firstDayOfMonth - firstDayOfWeek + 7) % 7;
|
|
113
113
|
};
|
|
114
114
|
const getWeekdayNames = locale => {
|
|
@@ -124,18 +124,15 @@ const getCalendarDayLabel = (day, timeZone) => moment.tz(day, timeZone).format('
|
|
|
124
124
|
const createItemDateTimeToString = (locale, timeZone) => item => item ? formatDate(item, locale, timeZone) : '';
|
|
125
125
|
const createCalendarItems = (day, timeString, timeZone) => {
|
|
126
126
|
var _context2;
|
|
127
|
-
|
|
128
127
|
const parsedTime = parseTime(timeString);
|
|
129
128
|
return _mapInstanceProperty(_context2 = _Array$from({
|
|
130
129
|
length: getDaysInMonth(day, timeZone)
|
|
131
130
|
})).call(_context2, (_, i) => {
|
|
132
131
|
const dayOfMonth = i + 1;
|
|
133
132
|
let date = changeDateInMonth(day, timeZone, dayOfMonth);
|
|
134
|
-
|
|
135
133
|
if (parsedTime) {
|
|
136
134
|
date = changeTime(date, timeZone, parsedTime);
|
|
137
135
|
}
|
|
138
|
-
|
|
139
136
|
return date;
|
|
140
137
|
});
|
|
141
138
|
};
|
|
@@ -146,16 +143,14 @@ const createSuggestedItems = (inputValue, timeZone) => {
|
|
|
146
143
|
const parseInputText = (text, locale, timeZone) => {
|
|
147
144
|
const parts = text.split(' ');
|
|
148
145
|
const dateString = parts[0];
|
|
149
|
-
|
|
150
146
|
const timeString = _sliceInstanceProperty(parts).call(parts, 1).join(' ');
|
|
151
|
-
|
|
152
147
|
if (!dateString) return '';
|
|
153
148
|
const date = moment.tz(dateString, moment.localeData(locale).longDateFormat('L'), timeZone);
|
|
154
|
-
if (!date.isValid()) return '';
|
|
149
|
+
if (!date.isValid()) return '';
|
|
155
150
|
|
|
151
|
+
// enable parsing a date only
|
|
156
152
|
if (!timeString) return date.startOf('day').toISOString();
|
|
157
153
|
const parsedTime = parseTime(timeString);
|
|
158
|
-
|
|
159
154
|
if (parsedTime) {
|
|
160
155
|
date.hours(parsedTime.hours);
|
|
161
156
|
date.minutes(parsedTime.minutes);
|
|
@@ -164,71 +159,59 @@ const parseInputText = (text, locale, timeZone) => {
|
|
|
164
159
|
date.milliseconds(parsedTime.milliseconds);
|
|
165
160
|
return date.toISOString();
|
|
166
161
|
}
|
|
167
|
-
|
|
168
162
|
return '';
|
|
169
163
|
};
|
|
170
164
|
const localizedDateFormatPatternCache = new _Map();
|
|
171
165
|
const getLocalizedDateTimeFormatPattern = function (locale) {
|
|
172
166
|
var _context3, _context4;
|
|
173
|
-
|
|
174
167
|
let formatType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
|
|
175
|
-
|
|
176
168
|
const key = _concatInstanceProperty(_context3 = "".concat(locale, "::")).call(_context3, formatType);
|
|
177
|
-
|
|
178
169
|
if (localizedDateFormatPatternCache.has(key)) {
|
|
179
170
|
return localizedDateFormatPatternCache.get(key);
|
|
180
|
-
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// References:
|
|
181
174
|
// https://momentjs.com/docs/#/i18n/locale-data/
|
|
182
175
|
// https://momentjs.com/docs/#/displaying/ ("Localized formats" section)
|
|
183
|
-
|
|
184
|
-
|
|
185
176
|
const localeData = moment().locale(locale).localeData();
|
|
186
177
|
let localizedFormat = '';
|
|
187
|
-
|
|
188
178
|
switch (formatType) {
|
|
189
179
|
case 'date':
|
|
190
180
|
localizedFormat = localeData.longDateFormat('L');
|
|
191
181
|
break;
|
|
192
|
-
|
|
193
182
|
case 'time':
|
|
194
183
|
localizedFormat = localeData.longDateFormat('LT');
|
|
195
184
|
break;
|
|
196
|
-
|
|
197
185
|
case 'full':
|
|
198
186
|
localizedFormat = _concatInstanceProperty(_context4 = "".concat(localeData.longDateFormat('L'), " - ")).call(_context4, localeData.longDateFormat('LT'));
|
|
199
187
|
break;
|
|
200
|
-
|
|
201
188
|
default:
|
|
202
189
|
throw new Error("CalendarTime.getLocalizedDateTimeFormatPattern: Unknown format type '".concat(formatType, "'"));
|
|
203
|
-
}
|
|
204
|
-
// and the generic language code (e.g. 'en').
|
|
205
|
-
|
|
190
|
+
}
|
|
206
191
|
|
|
192
|
+
// We try to get the localization both with the whole locale (e.g. 'en-GB')
|
|
193
|
+
// and the generic language code (e.g. 'en').
|
|
207
194
|
const _locale$split = locale.split('-'),
|
|
208
|
-
|
|
209
|
-
|
|
195
|
+
_locale$split2 = _slicedToArray(_locale$split, 1),
|
|
196
|
+
languageCode = _locale$split2[0];
|
|
197
|
+
const localeMappings = _Object$entries(DATE_FORMAT_LOCALIZED_MAPPINGS[locale] || DATE_FORMAT_LOCALIZED_MAPPINGS[languageCode] || {});
|
|
210
198
|
|
|
211
|
-
|
|
199
|
+
// In case we don't have a translation for the locale, we fallback to the
|
|
212
200
|
// pattern from the moment locale data.
|
|
213
|
-
|
|
214
|
-
|
|
215
201
|
let pattern = localizedFormat;
|
|
216
|
-
|
|
217
202
|
if (localeMappings && localeMappings.length > 0) {
|
|
218
203
|
pattern = _reduceInstanceProperty(localeMappings).call(localeMappings, (localizedPattern, _ref) => {
|
|
219
204
|
let _ref2 = _slicedToArray(_ref, 2),
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
205
|
+
token = _ref2[0],
|
|
206
|
+
mappedValue = _ref2[1];
|
|
223
207
|
return localizedPattern.replace(token, mappedValue);
|
|
224
208
|
}, localizedFormat);
|
|
225
209
|
}
|
|
226
|
-
|
|
227
210
|
localizedDateFormatPatternCache.set(key, pattern);
|
|
228
211
|
return pattern;
|
|
229
212
|
};
|
|
230
213
|
|
|
231
214
|
// NOTE: This string will be replaced on build time with the package version.
|
|
232
|
-
var version = "16.
|
|
215
|
+
var version = "16.1.1";
|
|
233
216
|
|
|
234
217
|
export { changeDateInMonth, changeMonth, changeTime, createCalendarItems, createItemDateTimeToString, createSuggestedItems, formatDate, 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": "16.
|
|
4
|
+
"version": "16.1.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": "16.
|
|
24
|
+
"@commercetools-uikit/utils": "16.1.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"moment-timezone": "0.5.43"
|