@progress/kendo-dateinputs-common 0.2.0-dev.202301061353 → 0.2.0-dev.202301130811
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/CODEOWNERS +2 -0
- package/dist/cdn/js/kendo-dateinputs-common.js +1 -1
- package/dist/cdn/main.js +1 -1
- package/dist/es/common/dateobject.js +280 -161
- package/dist/es/common/utils.js +1 -1
- package/dist/es/dateinput/dateinput.js +115 -46
- package/dist/es/dateinput/utils.js +10 -14
- package/dist/es2015/common/dateobject.js +280 -161
- package/dist/es2015/common/utils.js +1 -1
- package/dist/es2015/dateinput/dateinput.js +114 -45
- package/dist/es2015/dateinput/utils.js +10 -14
- package/dist/npm/common/dateobject.d.ts +6 -1
- package/dist/npm/common/dateobject.js +279 -160
- package/dist/npm/common/utils.d.ts +1 -1
- package/dist/npm/common/utils.js +1 -1
- package/dist/npm/dateinput/dateinput.d.ts +13 -2
- package/dist/npm/dateinput/dateinput.js +114 -45
- package/dist/npm/dateinput/utils.js +10 -14
- package/dist/systemjs/kendo-dateinputs-common.js +1 -1
- package/global-setup.js +4 -0
- package/jest.config.js +9 -0
- package/package.json +4 -4
|
@@ -160,16 +160,18 @@ var DateObject = /** @class */ (function () {
|
|
|
160
160
|
partiallyInvalidText += text[i];
|
|
161
161
|
}
|
|
162
162
|
else if (this.getInvalidDatePartValue(symbol)) {
|
|
163
|
+
var partsForSegment = this.getPartsForSegment(mask, i);
|
|
163
164
|
if (symbol === "M") {
|
|
164
|
-
|
|
165
|
+
var datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
|
|
166
|
+
if (partsForSegment.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
|
|
165
167
|
partiallyInvalidText += formattedDates[symbol][i];
|
|
166
168
|
}
|
|
167
169
|
else {
|
|
168
170
|
if (this.getInvalidDatePartValue(symbol)) {
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
i +=
|
|
171
|
+
var formattedDatePart = utils_1.padZero(partsForSegment.length - datePartText.length) + datePartText;
|
|
172
|
+
partiallyInvalidText += formattedDatePart;
|
|
173
|
+
// add -1 as the first character in the segment is at index i
|
|
174
|
+
i += partsForSegment.length - 1;
|
|
173
175
|
}
|
|
174
176
|
else {
|
|
175
177
|
partiallyInvalidText += formattedDates[symbol][i];
|
|
@@ -178,8 +180,11 @@ var DateObject = /** @class */ (function () {
|
|
|
178
180
|
}
|
|
179
181
|
else {
|
|
180
182
|
if (this.getInvalidDatePartValue(symbol)) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
var datePartText = this.getInvalidDatePartValue(symbol).toString();
|
|
184
|
+
var formattedDatePart = utils_1.padZero(partsForSegment.length - datePartText.length) + datePartText;
|
|
185
|
+
partiallyInvalidText += formattedDatePart;
|
|
186
|
+
// add -1 as the first character in the segment is at index i
|
|
187
|
+
i += partsForSegment.length - 1;
|
|
183
188
|
}
|
|
184
189
|
else {
|
|
185
190
|
partiallyInvalidText += formattedDates[symbol][i];
|
|
@@ -290,16 +295,18 @@ var DateObject = /** @class */ (function () {
|
|
|
290
295
|
}
|
|
291
296
|
};
|
|
292
297
|
DateObject.prototype.modifyPart = function (symbol, offset) {
|
|
298
|
+
if (!utils_2.isPresent(symbol) || !utils_2.isPresent(offset) || offset === 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
293
301
|
var newValue = kendo_date_math_1.cloneDate(this.value);
|
|
294
|
-
var originalValue = kendo_date_math_1.cloneDate(this.value);
|
|
295
302
|
var timeModified = false;
|
|
296
303
|
var invalidDateFound;
|
|
297
|
-
var
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
304
|
+
var isMonth = symbol === "M";
|
|
305
|
+
var isDay = symbol === "d" || symbol === "E";
|
|
306
|
+
var symbolExists = this.getExisting(symbol);
|
|
307
|
+
if (!this.autoCorrectParts && (isDay || isMonth)) {
|
|
301
308
|
var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
|
|
302
|
-
var
|
|
309
|
+
var invalidDatePartValue = this.getInvalidDatePartValue(symbol);
|
|
303
310
|
var year = invalidDateParts.y.value || newValue.getFullYear();
|
|
304
311
|
var month = invalidDateParts.M.value || newValue.getMonth();
|
|
305
312
|
var day = invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
|
|
@@ -318,33 +325,61 @@ var DateObject = /** @class */ (function () {
|
|
|
318
325
|
case 'E':
|
|
319
326
|
day += offset;
|
|
320
327
|
break;
|
|
321
|
-
case 'h':
|
|
322
|
-
case 'H':
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
case '
|
|
326
|
-
minutes += offset;
|
|
327
|
-
break;
|
|
328
|
-
case 's':
|
|
329
|
-
seconds += offset;
|
|
330
|
-
break;
|
|
331
|
-
case 'S':
|
|
332
|
-
milliseconds += offset;
|
|
333
|
-
break;
|
|
334
|
-
// case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
|
|
328
|
+
// case 'h':
|
|
329
|
+
// case 'H': hour += offset; break;
|
|
330
|
+
// case 'm': minutes += offset; break;
|
|
331
|
+
// case 's': seconds += offset; break;
|
|
332
|
+
// case 'S': milliseconds += offset; break;
|
|
335
333
|
default: break;
|
|
336
334
|
}
|
|
337
335
|
if (symbol === "M") {
|
|
338
|
-
if ((month < 0 || month > 11)
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
336
|
+
if ((month < 0 || month > 11)) {
|
|
337
|
+
if (symbolExists) {
|
|
338
|
+
this.setExisting(symbol, false);
|
|
339
|
+
this.resetInvalidDateSymbol(symbol);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (!symbolExists) {
|
|
344
|
+
if (month < 0) {
|
|
345
|
+
month = utils_2.clamp(11 + ((month % 11) + 1), 0, 11);
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
var monthValue = utils_2.isPresent(invalidDatePartValue) ?
|
|
349
|
+
month :
|
|
350
|
+
((offset - JS_MONTH_OFFSET) % 12);
|
|
351
|
+
month = utils_2.clamp(monthValue, 0, 11);
|
|
352
|
+
}
|
|
353
|
+
month = utils_2.clamp(month, 0, 11);
|
|
354
|
+
}
|
|
355
|
+
month = utils_2.clamp(month, 0, 11);
|
|
356
|
+
}
|
|
357
|
+
else if (symbol === "d") {
|
|
358
|
+
if (symbolExists) {
|
|
359
|
+
if (day <= 0 || day > 31) {
|
|
360
|
+
this.setExisting(symbol, false);
|
|
361
|
+
this.resetInvalidDateSymbol(symbol);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else if (!symbolExists) {
|
|
366
|
+
if (utils_2.isPresent(invalidDatePartValue)) {
|
|
367
|
+
if (day <= 0 || day > 31) {
|
|
368
|
+
this.setExisting(symbol, false);
|
|
369
|
+
this.resetInvalidDateSymbol(symbol);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (offset < 0) {
|
|
374
|
+
var dayValue = utils_2.isPresent(invalidDatePartValue) ? day : 1 + (31 - Math.abs(offset % 31));
|
|
375
|
+
day = utils_2.clamp(dayValue, 1, 31);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
var dayValue = utils_2.isPresent(invalidDatePartValue) ? day : offset % 31;
|
|
379
|
+
day = utils_2.clamp(dayValue, 1, 31);
|
|
380
|
+
}
|
|
381
|
+
day = utils_2.clamp(day, 1, 31);
|
|
342
382
|
}
|
|
343
|
-
// const mask = this.dateFormatString(this.value, this.format);
|
|
344
|
-
// const monthPart = mask.partMap.filter(x => x.type === "month");
|
|
345
|
-
// if (monthPart && monthPart[0] && monthPart[0].pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
|
|
346
|
-
month = (12 + month) % 12;
|
|
347
|
-
// }
|
|
348
383
|
}
|
|
349
384
|
var dateCandidate = kendo_date_math_1.createDate(year, month, day, hour, minutes, seconds, milliseconds);
|
|
350
385
|
var newValueCandidate = isMonth || isDay ?
|
|
@@ -441,92 +476,6 @@ var DateObject = /** @class */ (function () {
|
|
|
441
476
|
this.setExisting(symbol, false);
|
|
442
477
|
}
|
|
443
478
|
}
|
|
444
|
-
else {
|
|
445
|
-
// this.modifyDateSymbol()
|
|
446
|
-
switch (symbol) {
|
|
447
|
-
case 'y':
|
|
448
|
-
newValue.setFullYear(newValue.getFullYear() + offset);
|
|
449
|
-
break;
|
|
450
|
-
case 'M':
|
|
451
|
-
newValue = kendo_date_math_1.addMonths(this.value, offset);
|
|
452
|
-
break;
|
|
453
|
-
case 'd':
|
|
454
|
-
case 'E':
|
|
455
|
-
newValue.setDate(newValue.getDate() + offset);
|
|
456
|
-
break;
|
|
457
|
-
case 'h':
|
|
458
|
-
case 'H':
|
|
459
|
-
newValue.setHours(newValue.getHours() + offset);
|
|
460
|
-
timeModified = true;
|
|
461
|
-
break;
|
|
462
|
-
case 'm':
|
|
463
|
-
newValue.setMinutes(newValue.getMinutes() + offset);
|
|
464
|
-
timeModified = true;
|
|
465
|
-
break;
|
|
466
|
-
case 's':
|
|
467
|
-
newValue.setSeconds(newValue.getSeconds() + offset);
|
|
468
|
-
timeModified = true;
|
|
469
|
-
break;
|
|
470
|
-
case "S":
|
|
471
|
-
newValue.setMilliseconds(newValue.getMilliseconds() + offset);
|
|
472
|
-
break;
|
|
473
|
-
case 'a':
|
|
474
|
-
newValue.setHours(newValue.getHours() + (12 * offset));
|
|
475
|
-
timeModified = true;
|
|
476
|
-
break;
|
|
477
|
-
default: break;
|
|
478
|
-
}
|
|
479
|
-
invalidDateFound = true;
|
|
480
|
-
if (invalidDatePart && invalidDatePart.value) {
|
|
481
|
-
currentInvalidDatePartValue = utils_2.parseToInt(invalidDatePart.value);
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
if (!utils_2.isPresent(invalidDatePart.value)) {
|
|
485
|
-
newValue = kendo_date_math_1.cloneDate(originalValue);
|
|
486
|
-
// this.modifyDateSymbol()
|
|
487
|
-
switch (symbol) {
|
|
488
|
-
case 'y':
|
|
489
|
-
currentInvalidDatePartValue = originalValue.getFullYear();
|
|
490
|
-
break;
|
|
491
|
-
case 'M':
|
|
492
|
-
currentInvalidDatePartValue = originalValue.getMonth();
|
|
493
|
-
break;
|
|
494
|
-
case 'd':
|
|
495
|
-
case 'E':
|
|
496
|
-
currentInvalidDatePartValue = originalValue.getDate();
|
|
497
|
-
break;
|
|
498
|
-
case 'h':
|
|
499
|
-
case 'H':
|
|
500
|
-
currentInvalidDatePartValue = originalValue.getHours();
|
|
501
|
-
break;
|
|
502
|
-
case 'm':
|
|
503
|
-
currentInvalidDatePartValue = originalValue.getMinutes();
|
|
504
|
-
break;
|
|
505
|
-
case 's':
|
|
506
|
-
currentInvalidDatePartValue = originalValue.getSeconds();
|
|
507
|
-
break;
|
|
508
|
-
case 'S':
|
|
509
|
-
currentInvalidDatePartValue = originalValue.getMilliseconds();
|
|
510
|
-
break;
|
|
511
|
-
// case 'a': newValue.setHours(newValue.getHours() + (12 * offset)); timeModified = true; break;
|
|
512
|
-
default: break;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
var invalidDatePartValue = Math.max(0, currentInvalidDatePartValue + offset);
|
|
519
|
-
if (symbol !== "y") {
|
|
520
|
-
invalidDatePartValue = utils_2.clamp(currentInvalidDatePartValue + offset, 0, 99);
|
|
521
|
-
}
|
|
522
|
-
this.setInvalidDatePart(symbol, {
|
|
523
|
-
value: invalidDatePartValue,
|
|
524
|
-
date: kendo_date_math_1.cloneDate(newValue),
|
|
525
|
-
startDateOffset: (this.getInvalidDatePart(symbol).startDateOffset || 0) + offset,
|
|
526
|
-
startDate: kendo_date_math_1.cloneDate(this.value)
|
|
527
|
-
});
|
|
528
|
-
this.setExisting(symbol, false);
|
|
529
|
-
}
|
|
530
479
|
}
|
|
531
480
|
else {
|
|
532
481
|
switch (symbol) {
|
|
@@ -585,7 +534,7 @@ var DateObject = /** @class */ (function () {
|
|
|
585
534
|
*/
|
|
586
535
|
DateObject.prototype.parsePart = function (_a) {
|
|
587
536
|
var _b;
|
|
588
|
-
var symbol = _a.symbol, currentChar = _a.currentChar, resetSegmentValue = _a.resetSegmentValue, cycleSegmentValue = _a.cycleSegmentValue,
|
|
537
|
+
var symbol = _a.symbol, currentChar = _a.currentChar, resetSegmentValue = _a.resetSegmentValue, cycleSegmentValue = _a.cycleSegmentValue, rawInputValue = _a.rawTextValue, isDeleting = _a.isDeleting, originalFormat = _a.originalFormat;
|
|
589
538
|
var isInCaretMode = !cycleSegmentValue;
|
|
590
539
|
var dateParts = this.dateFormatString(this.value, this.format);
|
|
591
540
|
var datePartsLiterals = dateParts.partMap
|
|
@@ -593,9 +542,20 @@ var DateObject = /** @class */ (function () {
|
|
|
593
542
|
.map(function (x, index) {
|
|
594
543
|
return {
|
|
595
544
|
datePartIndex: index,
|
|
596
|
-
|
|
545
|
+
type: x.type,
|
|
546
|
+
pattern: x.pattern,
|
|
547
|
+
literal: ""
|
|
597
548
|
};
|
|
598
549
|
});
|
|
550
|
+
for (var i = 0; i < datePartsLiterals.length; i++) {
|
|
551
|
+
var datePart = datePartsLiterals[i];
|
|
552
|
+
for (var j = 0; j < datePart.pattern.length; j++) {
|
|
553
|
+
if (datePartsLiterals[i + j]) {
|
|
554
|
+
datePartsLiterals[i + j].literal = datePart.pattern[j];
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
i += datePart.pattern.length - 1;
|
|
558
|
+
}
|
|
599
559
|
var shouldResetPart = isInCaretMode && symbol === "M" && dateParts.partMap
|
|
600
560
|
.filter(function (x) { return x.type === "month"; })
|
|
601
561
|
.some(function (x) { return x.pattern.length > MONTH_PART_WITH_WORDS_THRESHOLD; });
|
|
@@ -608,9 +568,9 @@ var DateObject = /** @class */ (function () {
|
|
|
608
568
|
if (isInCaretMode) {
|
|
609
569
|
for (var i = 0; i < datePartsLiterals.length; i++) {
|
|
610
570
|
var literal = datePartsLiterals[i].literal;
|
|
611
|
-
var rawValueStartsWithLiteral =
|
|
612
|
-
var rawValueEndsWithLiteral =
|
|
613
|
-
var rawValueHasConsecutiveLiterals =
|
|
571
|
+
var rawValueStartsWithLiteral = rawInputValue.startsWith(literal);
|
|
572
|
+
var rawValueEndsWithLiteral = rawInputValue.endsWith(literal);
|
|
573
|
+
var rawValueHasConsecutiveLiterals = rawInputValue.indexOf(literal + literal) >= 0;
|
|
614
574
|
if (rawValueStartsWithLiteral || rawValueEndsWithLiteral || rawValueHasConsecutiveLiterals) {
|
|
615
575
|
this.resetLeadingZero();
|
|
616
576
|
this.setExisting(symbol, false);
|
|
@@ -633,38 +593,82 @@ var DateObject = /** @class */ (function () {
|
|
|
633
593
|
var prefix = '';
|
|
634
594
|
var current = '';
|
|
635
595
|
var datePartText = '';
|
|
596
|
+
var basePrefix = '';
|
|
597
|
+
var baseSuffix = '';
|
|
636
598
|
var suffix = '';
|
|
599
|
+
var datePartStartIndex = originalFormat.indexOf(symbol);
|
|
600
|
+
var datePartEndIndex = originalFormat.lastIndexOf(symbol);
|
|
601
|
+
var segmentLength = datePartEndIndex - datePartStartIndex + 1;
|
|
602
|
+
var hasFixedFormat = (this.format === baseFormat) ||
|
|
603
|
+
(this.format === originalFormat) ||
|
|
604
|
+
(this.format.length === originalFormat.length);
|
|
637
605
|
if (isInCaretMode) {
|
|
638
|
-
var
|
|
639
|
-
var outOfDatePartBounds = false;
|
|
606
|
+
var processedSegmentCharsCount = 0;
|
|
640
607
|
for (var i = 0; i < baseDate.length; i++) {
|
|
641
|
-
var datePartLiteral = datePartsLiterals[datePartIndex];
|
|
642
|
-
if (datePartLiteral && datePartLiteral === baseDate[i]) {
|
|
643
|
-
datePartIndex++;
|
|
644
|
-
}
|
|
645
608
|
if (baseFormat[i] === symbol) {
|
|
646
609
|
var existing = this.getExisting(symbol);
|
|
647
610
|
current += existing ? baseDate[i] : '0';
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
else if (!outOfDatePartBounds) {
|
|
653
|
-
if (rawInputChar === undefined) {
|
|
654
|
-
var formatOffset = Math.abs(this.format.length - baseFormat.length);
|
|
655
|
-
datePartText += rawTextValue[i - formatOffset] || '';
|
|
656
|
-
}
|
|
657
|
-
else {
|
|
658
|
-
datePartText += rawInputChar || '';
|
|
611
|
+
if (isDeleting) {
|
|
612
|
+
// when deleting, process (segmentLength - 1) chars
|
|
613
|
+
if (processedSegmentCharsCount < segmentLength - 1) {
|
|
614
|
+
datePartText += rawInputValue[i] || "";
|
|
659
615
|
}
|
|
616
|
+
processedSegmentCharsCount++;
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
datePartText += rawInputValue[i] || "";
|
|
660
620
|
}
|
|
661
621
|
replaced = true;
|
|
662
622
|
}
|
|
663
623
|
else if (!replaced) {
|
|
664
624
|
prefix += baseDate[i];
|
|
625
|
+
basePrefix += baseDate[i];
|
|
665
626
|
}
|
|
666
627
|
else {
|
|
667
628
|
suffix += baseDate[i];
|
|
629
|
+
baseSuffix += baseDate[i];
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if (hasFixedFormat) {
|
|
633
|
+
if (originalFormat.length < rawInputValue.length) {
|
|
634
|
+
datePartText += currentChar;
|
|
635
|
+
}
|
|
636
|
+
if (datePartText.length > segmentLength) {
|
|
637
|
+
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
processedSegmentCharsCount = 0;
|
|
642
|
+
current = "";
|
|
643
|
+
datePartText = "";
|
|
644
|
+
prefix = "";
|
|
645
|
+
suffix = "";
|
|
646
|
+
replaced = false;
|
|
647
|
+
for (var i = 0; i < originalFormat.length; i++) {
|
|
648
|
+
if (originalFormat[i] === symbol) {
|
|
649
|
+
var existing = this.getExisting(symbol);
|
|
650
|
+
current += existing ? baseDate[i] || "" : '0';
|
|
651
|
+
if (isDeleting) {
|
|
652
|
+
// when deleting, process (segmentLength - 1) chars
|
|
653
|
+
if (processedSegmentCharsCount < segmentLength - 1) {
|
|
654
|
+
datePartText += rawInputValue[i] || "";
|
|
655
|
+
}
|
|
656
|
+
processedSegmentCharsCount++;
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
datePartText += rawInputValue[i] || "";
|
|
660
|
+
}
|
|
661
|
+
replaced = true;
|
|
662
|
+
}
|
|
663
|
+
else if (!replaced) {
|
|
664
|
+
prefix += rawInputValue[i] || "";
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
suffix += rawInputValue[i] || "";
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
if (originalFormat.length < rawInputValue.length) {
|
|
671
|
+
datePartText += currentChar;
|
|
668
672
|
}
|
|
669
673
|
}
|
|
670
674
|
}
|
|
@@ -699,10 +703,6 @@ var DateObject = /** @class */ (function () {
|
|
|
699
703
|
}
|
|
700
704
|
var partPattern = this.partPattern(dateParts.partMap, symbol);
|
|
701
705
|
var patternValue = partPattern ? partPattern.pattern : null;
|
|
702
|
-
if (isInCaretMode && isDeleting) {
|
|
703
|
-
var padPrefix = utils_1.padZero(Math.abs(current.length - datePartText.length));
|
|
704
|
-
current = padPrefix + datePartText;
|
|
705
|
-
}
|
|
706
706
|
if (isInCaretMode) {
|
|
707
707
|
if (isDeleting && !datePartText) {
|
|
708
708
|
this.setExisting(symbol, false);
|
|
@@ -718,14 +718,30 @@ var DateObject = /** @class */ (function () {
|
|
|
718
718
|
if (!this.autoCorrectParts) {
|
|
719
719
|
tryParse = false;
|
|
720
720
|
}
|
|
721
|
-
var middle = resetSegmentValue ?
|
|
722
|
-
|
|
721
|
+
var middle = resetSegmentValue ?
|
|
722
|
+
currentChar :
|
|
723
|
+
isInCaretMode ?
|
|
724
|
+
datePartText :
|
|
725
|
+
(current.substring(i) + currentChar);
|
|
726
|
+
if (isInCaretMode) {
|
|
723
727
|
// try to make an exact match as there will be only 1 attempt
|
|
728
|
+
tryParse = false;
|
|
724
729
|
middle = utils_1.unpadZero(middle);
|
|
725
730
|
}
|
|
726
731
|
var middleNumber = parseInt(middle, 10);
|
|
727
732
|
var candidateDateString = prefix + middle + suffix;
|
|
728
733
|
parsedDate = this.intl.parseDate(candidateDateString, this.format, this.localeId);
|
|
734
|
+
if (isInCaretMode && !hasFixedFormat && !utils_2.isValidDate(parsedDate)) {
|
|
735
|
+
// if part of the date is not available, e.g. "d"
|
|
736
|
+
// but an expanded format like "F" is used
|
|
737
|
+
// the element value can be "EEEE, February 1, 2022 3:04:05 AM"
|
|
738
|
+
// which is not parsable by intl
|
|
739
|
+
// use the base prefix and suffix, e.g. convert the candidate date string
|
|
740
|
+
// to "Thursday, February 1, 2022 3:04:05 AM"
|
|
741
|
+
// as "EEEE, February..." is not parsable
|
|
742
|
+
parsedDate = this.intl.parseDate(basePrefix + middle + baseSuffix, this.format, this.localeId);
|
|
743
|
+
datePartText = middle;
|
|
744
|
+
}
|
|
729
745
|
var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
|
|
730
746
|
if (!parsedDate && !isNaN(middleNumber) && isCurrentCharParsable) {
|
|
731
747
|
if (symbol === MONTH_SYMBOL && !month) {
|
|
@@ -741,23 +757,47 @@ var DateObject = /** @class */ (function () {
|
|
|
741
757
|
}
|
|
742
758
|
if (symbol === 'y') {
|
|
743
759
|
parsedDate = kendo_date_math_1.createDate(parseInt(middle, 10), this.month ? this.value.getMonth() : 0, this.date ? this.value.getDate() : 1, this.hours ? this.value.getHours() : 0, this.minutes ? this.value.getMinutes() : 0, this.seconds ? this.value.getSeconds() : 0, this.milliseconds ? this.value.getMilliseconds() : 0);
|
|
744
|
-
if (
|
|
760
|
+
if (((isInCaretMode && utils_2.isValidDate(parsedDate)) ||
|
|
761
|
+
(!isInCaretMode && parsedDate)) && this.date && parsedDate.getDate() !== this.value.getDate()) {
|
|
745
762
|
parsedDate = kendo_date_math_1.lastDayOfMonth(kendo_date_math_1.addMonths(parsedDate, -1));
|
|
746
763
|
}
|
|
747
764
|
}
|
|
748
765
|
}
|
|
749
|
-
if (parsedDate) {
|
|
766
|
+
if ((isInCaretMode && utils_2.isValidDate(parsedDate)) || (!isInCaretMode && parsedDate)) {
|
|
750
767
|
// move to next segment if the part will overflow with next char
|
|
751
768
|
// when start from empty date (01, then 010), padded zeros should be trimmed
|
|
752
769
|
var peekDate = this.intl.parseDate("" + prefix + this.peek(middle, patternValue) + suffix, this.format, this.localeId);
|
|
753
770
|
var patternLength = this.patternLength(patternValue) || patternValue.length;
|
|
754
|
-
var
|
|
755
|
-
var
|
|
771
|
+
var leadingZeroOffset = (this.leadingZero || {})[symbol] || 0;
|
|
772
|
+
var patternSatisfied = (leadingZeroOffset + (utils_1.unpadZero(middle) || currentChar).length) >= patternLength;
|
|
773
|
+
var switchToNext = peekDate === null ||
|
|
774
|
+
(leadingZero[symbol] && patternValue.length <= middle.length) ||
|
|
775
|
+
patternSatisfied;
|
|
756
776
|
if (this.shouldNormalizeCentury()) {
|
|
757
777
|
parsedDate = this.normalizeCentury(parsedDate);
|
|
758
778
|
}
|
|
759
779
|
this._value = parsedDate;
|
|
760
780
|
this.setExisting(symbol, true);
|
|
781
|
+
if (isInCaretMode && switchToNext) {
|
|
782
|
+
if (symbol === "M") {
|
|
783
|
+
if (segmentLength <= MONTH_PART_WITH_WORDS_THRESHOLD) {
|
|
784
|
+
var datePartValue = utils_2.parseToInt(datePartText);
|
|
785
|
+
if (datePartValue >= 2) {
|
|
786
|
+
switchToNext = true;
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
switchToNext = false;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
switchToNext = switchToNext ?
|
|
795
|
+
hasFixedFormat ?
|
|
796
|
+
datePartText.length === segmentLength :
|
|
797
|
+
datePartText.length > segmentLength :
|
|
798
|
+
switchToNext;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
761
801
|
return utils_2.extend(parseResult, { value: this.value, switchToNext: switchToNext });
|
|
762
802
|
}
|
|
763
803
|
}
|
|
@@ -780,6 +820,9 @@ var DateObject = /** @class */ (function () {
|
|
|
780
820
|
this.leadingZero = !this.isAbbrMonth(dateParts.partMap, symbol) ? (_b = {}, _b[symbol] = true, _b) : null;
|
|
781
821
|
this.setExisting(symbol, false);
|
|
782
822
|
}
|
|
823
|
+
if (isInCaretMode && datePartText.length > segmentLength) {
|
|
824
|
+
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
825
|
+
}
|
|
783
826
|
if (!this.autoCorrectParts) {
|
|
784
827
|
this.setExisting(symbol, false);
|
|
785
828
|
// todo check if string is better
|
|
@@ -795,11 +838,14 @@ var DateObject = /** @class */ (function () {
|
|
|
795
838
|
}
|
|
796
839
|
if (utils_2.isNumber(datePartValue)) {
|
|
797
840
|
var newDate = this.modifyDateSymbolWithValue(this.value, symbol, datePartValue);
|
|
841
|
+
// if (!isEqual(newDate, this.value)) {
|
|
842
|
+
this.setExisting(symbol, false);
|
|
798
843
|
this.setInvalidDatePart(symbol, {
|
|
799
844
|
value: datePartValue,
|
|
800
845
|
date: kendo_date_math_1.cloneDate(newDate),
|
|
801
846
|
startDate: this._partiallyInvalidDate.startDate || kendo_date_math_1.cloneDate(this.value)
|
|
802
847
|
});
|
|
848
|
+
// }
|
|
803
849
|
}
|
|
804
850
|
}
|
|
805
851
|
return utils_2.extend(parseResult, { value: null, switchToNext: false });
|
|
@@ -963,24 +1009,68 @@ var DateObject = /** @class */ (function () {
|
|
|
963
1009
|
var resultText = '';
|
|
964
1010
|
var resultFormat = '';
|
|
965
1011
|
var format = mask.symbols;
|
|
1012
|
+
var processTextSymbolsEnded = false;
|
|
1013
|
+
var ignoreFormatSymbolsCount = 0;
|
|
1014
|
+
var formattedDates = this.getFormattedInvalidDates(format);
|
|
966
1015
|
for (var formatSymbolIndex = format.length - 1; formatSymbolIndex >= 0; formatSymbolIndex--) {
|
|
1016
|
+
var partsForSegment = this.getPartsForSegment(mask, formatSymbolIndex);
|
|
967
1017
|
if (this.knownParts.indexOf(format[formatSymbolIndex]) === -1 || this.getExisting(format[formatSymbolIndex])) {
|
|
968
|
-
|
|
1018
|
+
if (this.autoCorrectParts) {
|
|
1019
|
+
resultText = text[formatSymbolIndex] + resultText;
|
|
1020
|
+
}
|
|
1021
|
+
else {
|
|
1022
|
+
if (text.length !== format.length) {
|
|
1023
|
+
if (processTextSymbolsEnded) {
|
|
1024
|
+
resultText = text[formatSymbolIndex] + resultText;
|
|
1025
|
+
}
|
|
1026
|
+
else if (ignoreFormatSymbolsCount > 0) {
|
|
1027
|
+
resultText = text[formatSymbolIndex] + resultText;
|
|
1028
|
+
ignoreFormatSymbolsCount--;
|
|
1029
|
+
if (ignoreFormatSymbolsCount <= 0) {
|
|
1030
|
+
processTextSymbolsEnded = true;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
else {
|
|
1034
|
+
resultText = (text[formatSymbolIndex + text.length - format.length] || "") + resultText;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
resultText = text[formatSymbolIndex] + resultText;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
969
1041
|
resultFormat = format[formatSymbolIndex] + resultFormat;
|
|
970
1042
|
}
|
|
971
1043
|
else {
|
|
972
1044
|
var symbol = format[formatSymbolIndex];
|
|
973
|
-
|
|
974
|
-
|
|
1045
|
+
var formatSymbolIndexModifier = 0;
|
|
1046
|
+
if (this.autoCorrectParts || (!this.autoCorrectParts && !this.getInvalidDatePartValue(symbol))) {
|
|
1047
|
+
while (formatSymbolIndex >= 0 && symbol === format[formatSymbolIndex]) {
|
|
1048
|
+
formatSymbolIndex--;
|
|
1049
|
+
}
|
|
1050
|
+
formatSymbolIndex++;
|
|
975
1051
|
}
|
|
976
|
-
formatSymbolIndex++;
|
|
977
1052
|
if (this.leadingZero && this.leadingZero[symbol]) {
|
|
978
1053
|
resultText = '0' + resultText;
|
|
979
1054
|
}
|
|
980
1055
|
else {
|
|
981
1056
|
if (!this.autoCorrectParts && this.getInvalidDatePartValue(symbol)) {
|
|
982
|
-
var
|
|
983
|
-
|
|
1057
|
+
var datePartText = this.getInvalidDatePartValue(symbol).toString();
|
|
1058
|
+
if (symbol === "M") {
|
|
1059
|
+
datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
|
|
1060
|
+
if (partsForSegment.length > MONTH_PART_WITH_WORDS_THRESHOLD) {
|
|
1061
|
+
resultText = formattedDates[symbol][formatSymbolIndex] + resultText;
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
datePartText = (utils_2.parseToInt(this.getInvalidDatePartValue(symbol)) + JS_MONTH_OFFSET).toString();
|
|
1065
|
+
resultText = datePartText + resultText;
|
|
1066
|
+
ignoreFormatSymbolsCount = datePartText.length - partsForSegment.length;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
resultText = datePartText + resultText;
|
|
1071
|
+
formatSymbolIndexModifier = datePartText.length - 1;
|
|
1072
|
+
ignoreFormatSymbolsCount = datePartText.length - partsForSegment.length;
|
|
1073
|
+
}
|
|
984
1074
|
}
|
|
985
1075
|
else {
|
|
986
1076
|
resultText = this.dateFieldName(mask.partMap[formatSymbolIndex]) + resultText;
|
|
@@ -989,6 +1079,9 @@ var DateObject = /** @class */ (function () {
|
|
|
989
1079
|
while (resultFormat.length < resultText.length) {
|
|
990
1080
|
resultFormat = format[formatSymbolIndex] + resultFormat;
|
|
991
1081
|
}
|
|
1082
|
+
if (formatSymbolIndexModifier !== 0) {
|
|
1083
|
+
formatSymbolIndex = (formatSymbolIndex - formatSymbolIndexModifier) + (text.length - format.length);
|
|
1084
|
+
}
|
|
992
1085
|
}
|
|
993
1086
|
}
|
|
994
1087
|
return { text: resultText, format: resultFormat };
|
|
@@ -1156,6 +1249,32 @@ var DateObject = /** @class */ (function () {
|
|
|
1156
1249
|
DateObject.prototype.markDatePartsAsExisting = function () {
|
|
1157
1250
|
this.modifyExisting(true);
|
|
1158
1251
|
};
|
|
1252
|
+
/**
|
|
1253
|
+
* @hidden
|
|
1254
|
+
*/
|
|
1255
|
+
DateObject.prototype.getPartsForSegment = function (mask, partIndex) {
|
|
1256
|
+
var segmentPart = mask.partMap[partIndex];
|
|
1257
|
+
var partsForSegment = [];
|
|
1258
|
+
for (var maskPartIndex = partIndex; maskPartIndex < mask.partMap.length; maskPartIndex++) {
|
|
1259
|
+
var part = mask.partMap[maskPartIndex];
|
|
1260
|
+
if (segmentPart.type === part.type && segmentPart.pattern === part.pattern) {
|
|
1261
|
+
partsForSegment.push(part);
|
|
1262
|
+
}
|
|
1263
|
+
else {
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
for (var maskPartIndex = partIndex - 1; maskPartIndex >= 0; maskPartIndex--) {
|
|
1268
|
+
var part = mask.partMap[maskPartIndex];
|
|
1269
|
+
if (segmentPart.type === part.type && segmentPart.pattern === part.pattern) {
|
|
1270
|
+
partsForSegment.unshift(part);
|
|
1271
|
+
}
|
|
1272
|
+
else {
|
|
1273
|
+
break;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return partsForSegment;
|
|
1277
|
+
};
|
|
1159
1278
|
return DateObject;
|
|
1160
1279
|
}());
|
|
1161
1280
|
exports.DateObject = DateObject;
|
package/dist/npm/common/utils.js
CHANGED
|
@@ -127,4 +127,4 @@ exports.areDatePartsEqualTo = function (date, year, month, day, hour, minutes, s
|
|
|
127
127
|
/**
|
|
128
128
|
* @hidden
|
|
129
129
|
*/
|
|
130
|
-
exports.
|
|
130
|
+
exports.isValidDate = function (value) { return exports.isPresent(value) && value.getTime && exports.isNumber(value.getTime()); };
|