@contentful/field-editor-date 2.0.16-canary.0 → 2.0.16
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.
|
@@ -68,9 +68,13 @@ const validInputFormats = [
|
|
|
68
68
|
'h'
|
|
69
69
|
];
|
|
70
70
|
const REF_DATE = new Date(2000, 0, 1);
|
|
71
|
+
function normalizeRawInput(raw) {
|
|
72
|
+
return raw.replace(/(\d)(am|pm)$/i, '$1 $2');
|
|
73
|
+
}
|
|
71
74
|
function parseRawInput(raw) {
|
|
75
|
+
const normalized = normalizeRawInput(raw);
|
|
72
76
|
for (const fmt of validInputFormats){
|
|
73
|
-
const parsed = (0, _datefns.parse)(
|
|
77
|
+
const parsed = (0, _datefns.parse)(normalized, fmt, REF_DATE);
|
|
74
78
|
if ((0, _datefns.isValid)(parsed)) return parsed;
|
|
75
79
|
}
|
|
76
80
|
return null;
|
|
@@ -234,6 +234,59 @@ describe('TimepickerInput', ()=>{
|
|
|
234
234
|
});
|
|
235
235
|
});
|
|
236
236
|
});
|
|
237
|
+
describe('am/pm without space separator', ()=>{
|
|
238
|
+
it('parses 1:15pm (no space) correctly in 12h mode', ()=>{
|
|
239
|
+
const onChange = jest.fn();
|
|
240
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
241
|
+
disabled: false,
|
|
242
|
+
uses12hClock: true,
|
|
243
|
+
time: "12:00",
|
|
244
|
+
ampm: "AM",
|
|
245
|
+
onChange: onChange
|
|
246
|
+
}));
|
|
247
|
+
_userevent.default.clear(getByTestId('time-input'));
|
|
248
|
+
_userevent.default.type(getByTestId('time-input'), '1:15pm');
|
|
249
|
+
_userevent.default.tab();
|
|
250
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
251
|
+
time: '01:15',
|
|
252
|
+
ampm: 'PM'
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
it('parses 1:15PM (no space, uppercase) correctly in 12h mode', ()=>{
|
|
256
|
+
const onChange = jest.fn();
|
|
257
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
258
|
+
disabled: false,
|
|
259
|
+
uses12hClock: true,
|
|
260
|
+
time: "12:00",
|
|
261
|
+
ampm: "AM",
|
|
262
|
+
onChange: onChange
|
|
263
|
+
}));
|
|
264
|
+
_userevent.default.clear(getByTestId('time-input'));
|
|
265
|
+
_userevent.default.type(getByTestId('time-input'), '1:15PM');
|
|
266
|
+
_userevent.default.tab();
|
|
267
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
268
|
+
time: '01:15',
|
|
269
|
+
ampm: 'PM'
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
it('parses 1pm (no space, no minutes) correctly in 12h mode', ()=>{
|
|
273
|
+
const onChange = jest.fn();
|
|
274
|
+
const { getByTestId } = (0, _react1.render)(/*#__PURE__*/ _react.createElement(_TimepickerInput.TimepickerInput, {
|
|
275
|
+
disabled: false,
|
|
276
|
+
uses12hClock: true,
|
|
277
|
+
time: "12:00",
|
|
278
|
+
ampm: "AM",
|
|
279
|
+
onChange: onChange
|
|
280
|
+
}));
|
|
281
|
+
_userevent.default.clear(getByTestId('time-input'));
|
|
282
|
+
_userevent.default.type(getByTestId('time-input'), '1pm');
|
|
283
|
+
_userevent.default.tab();
|
|
284
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
285
|
+
time: '01:00',
|
|
286
|
+
ampm: 'PM'
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
237
290
|
describe('onChange on blur — 12h mode', ()=>{
|
|
238
291
|
it('emits 07:00 AM correctly in 12h mode', ()=>{
|
|
239
292
|
const onChange = jest.fn();
|
|
@@ -17,9 +17,13 @@ const validInputFormats = [
|
|
|
17
17
|
'h'
|
|
18
18
|
];
|
|
19
19
|
const REF_DATE = new Date(2000, 0, 1);
|
|
20
|
+
function normalizeRawInput(raw) {
|
|
21
|
+
return raw.replace(/(\d)(am|pm)$/i, '$1 $2');
|
|
22
|
+
}
|
|
20
23
|
function parseRawInput(raw) {
|
|
24
|
+
const normalized = normalizeRawInput(raw);
|
|
21
25
|
for (const fmt of validInputFormats){
|
|
22
|
-
const parsed = parse(
|
|
26
|
+
const parsed = parse(normalized, fmt, REF_DATE);
|
|
23
27
|
if (isValid(parsed)) return parsed;
|
|
24
28
|
}
|
|
25
29
|
return null;
|
|
@@ -184,6 +184,59 @@ describe('TimepickerInput', ()=>{
|
|
|
184
184
|
});
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
|
+
describe('am/pm without space separator', ()=>{
|
|
188
|
+
it('parses 1:15pm (no space) correctly in 12h mode', ()=>{
|
|
189
|
+
const onChange = jest.fn();
|
|
190
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
191
|
+
disabled: false,
|
|
192
|
+
uses12hClock: true,
|
|
193
|
+
time: "12:00",
|
|
194
|
+
ampm: "AM",
|
|
195
|
+
onChange: onChange
|
|
196
|
+
}));
|
|
197
|
+
userEvent.clear(getByTestId('time-input'));
|
|
198
|
+
userEvent.type(getByTestId('time-input'), '1:15pm');
|
|
199
|
+
userEvent.tab();
|
|
200
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
201
|
+
time: '01:15',
|
|
202
|
+
ampm: 'PM'
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
it('parses 1:15PM (no space, uppercase) correctly in 12h mode', ()=>{
|
|
206
|
+
const onChange = jest.fn();
|
|
207
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
208
|
+
disabled: false,
|
|
209
|
+
uses12hClock: true,
|
|
210
|
+
time: "12:00",
|
|
211
|
+
ampm: "AM",
|
|
212
|
+
onChange: onChange
|
|
213
|
+
}));
|
|
214
|
+
userEvent.clear(getByTestId('time-input'));
|
|
215
|
+
userEvent.type(getByTestId('time-input'), '1:15PM');
|
|
216
|
+
userEvent.tab();
|
|
217
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
218
|
+
time: '01:15',
|
|
219
|
+
ampm: 'PM'
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
it('parses 1pm (no space, no minutes) correctly in 12h mode', ()=>{
|
|
223
|
+
const onChange = jest.fn();
|
|
224
|
+
const { getByTestId } = render(/*#__PURE__*/ React.createElement(TimepickerInput, {
|
|
225
|
+
disabled: false,
|
|
226
|
+
uses12hClock: true,
|
|
227
|
+
time: "12:00",
|
|
228
|
+
ampm: "AM",
|
|
229
|
+
onChange: onChange
|
|
230
|
+
}));
|
|
231
|
+
userEvent.clear(getByTestId('time-input'));
|
|
232
|
+
userEvent.type(getByTestId('time-input'), '1pm');
|
|
233
|
+
userEvent.tab();
|
|
234
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
235
|
+
time: '01:00',
|
|
236
|
+
ampm: 'PM'
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
187
240
|
describe('onChange on blur — 12h mode', ()=>{
|
|
188
241
|
it('emits 07:00 AM correctly in 12h mode', ()=>{
|
|
189
242
|
const onChange = jest.fn();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-date",
|
|
3
|
-
"version": "2.0.16
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@contentful/f36-components": "^6.7.1",
|
|
41
41
|
"@contentful/f36-tokens": "^6.1.2",
|
|
42
|
-
"@contentful/field-editor-shared": "^4.1.
|
|
42
|
+
"@contentful/field-editor-shared": "^4.1.1",
|
|
43
43
|
"@emotion/css": "^11.13.5",
|
|
44
44
|
"date-fns": "^2.30.0"
|
|
45
45
|
},
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"registry": "https://npm.pkg.github.com/"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5cb0e73547c3cbd7eafb34e9266e2f82358e79ac"
|
|
61
61
|
}
|