@progress/kendo-dateinputs-common 0.4.3-develop.1 → 0.4.3

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.
@@ -151,7 +151,6 @@ export class DateObject {
151
151
  // and a month that has 31 days
152
152
  // so that the default date can accommodate maximum date values
153
153
  // it is better to use a fixed date instead of new Date()
154
- // as otherwise the
155
154
  return createDate(DEFAULT_LEAP_YEAR, 0, 31);
156
155
  }
157
156
  /**
@@ -657,10 +656,28 @@ export class DateObject {
657
656
  const segmentLength = datePartEndIndex - datePartStartIndex + 1;
658
657
  const formatToTextLengthDiff = originalFormat.length - rawInputValue.length;
659
658
  if (isInCaretMode || (!isInCaretMode && !this.autoCorrectParts)) {
659
+ let segmentCharIndex = 0;
660
660
  for (let i = 0; i < baseDate.length; i++) {
661
661
  if (baseFormat[i] === symbol) {
662
662
  const existing = this.getExisting(symbol);
663
- current += existing ? baseDate[i] : '0';
663
+ if (symbol === "y") {
664
+ if (!this.hasInvalidDatePart() && this.getExisting("y")) {
665
+ current += baseDate[i];
666
+ }
667
+ else {
668
+ const invalidDatePartValue = this.getInvalidDatePartValue(symbol);
669
+ if (isPresent(invalidDatePartValue)) {
670
+ current += (invalidDatePartValue || "").toString()[segmentCharIndex] || "";
671
+ segmentCharIndex++;
672
+ }
673
+ else {
674
+ current += existing ? baseDate[i] : '0';
675
+ }
676
+ }
677
+ }
678
+ else {
679
+ current += existing ? baseDate[i] : '0';
680
+ }
664
681
  if (formatToTextLengthDiff > 0) {
665
682
  if (datePartText.length + formatToTextLengthDiff < segmentLength) {
666
683
  datePartText += rawInputValue[i] || "";
@@ -697,10 +714,28 @@ export class DateObject {
697
714
  prefix = "";
698
715
  suffix = "";
699
716
  replaced = false;
717
+ let segmentCharIndex = 0;
700
718
  for (let i = 0; i < originalFormat.length; i++) {
701
719
  if (originalFormat[i] === symbol) {
702
720
  const existing = this.getExisting(symbol);
703
- current += existing ? baseDate[i] || "" : '0';
721
+ if (symbol === "y") {
722
+ if (!this.hasInvalidDatePart() && this.getExisting("y")) {
723
+ current += baseDate[i];
724
+ }
725
+ else {
726
+ const invalidDatePartValue = this.getInvalidDatePartValue(symbol);
727
+ if (isPresent(invalidDatePartValue)) {
728
+ current += (invalidDatePartValue || "").toString()[segmentCharIndex] || "";
729
+ segmentCharIndex++;
730
+ }
731
+ else {
732
+ current += existing ? baseDate[i] : '0';
733
+ }
734
+ }
735
+ }
736
+ else {
737
+ current += existing ? baseDate[i] || "" : '0';
738
+ }
704
739
  if (formatToTextLengthDiff > 0) {
705
740
  if (datePartText.length + formatToTextLengthDiff < segmentLength) {
706
741
  datePartText += rawInputValue[i] || "";
@@ -749,7 +784,7 @@ export class DateObject {
749
784
  }
750
785
  }
751
786
  let parsedDate = null;
752
- const month = this.matchMonth(currentChar);
787
+ const monthByChar = this.matchMonth(currentChar);
753
788
  const dayPeriod = this.matchDayPeriod(currentChar, symbol);
754
789
  const isZeroCurrentChar = currentChar === '0';
755
790
  const leadingZero = this.leadingZero || {};
@@ -823,7 +858,7 @@ export class DateObject {
823
858
  }
824
859
  const isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
825
860
  if (!parsedDate && !isNaN(middleNumber) && isCurrentCharParsable && this.autoCorrectParts) {
826
- if (symbol === MONTH_SYMBOL && !month) {
861
+ if (symbol === MONTH_SYMBOL && !monthByChar) {
827
862
  // JS months start from 0 (January) instead of 1 (January)
828
863
  const monthNumber = middleNumber - JS_MONTH_OFFSET;
829
864
  if (monthNumber > -1 && monthNumber < 12) {
@@ -882,6 +917,10 @@ export class DateObject {
882
917
  this.resetInvalidDateSymbol("M");
883
918
  }
884
919
  }
920
+ else if (symbol === "y") {
921
+ // if the parsed date is valid, make the whole value valid
922
+ this.markDatePartsAsExisting();
923
+ }
885
924
  if (!this.hasInvalidDatePart()) {
886
925
  this.markDatePartsAsExisting();
887
926
  if (!peekResult.peekedDate && peekResult.switchToNext && !this.autoCorrectParts) {
@@ -904,8 +943,8 @@ export class DateObject {
904
943
  return extend(parseResult, { value: this.value, switchToNext: switchToNext });
905
944
  }
906
945
  }
907
- if (month) {
908
- parsedDate = this.intl.parseDate(prefix + month + suffix, this.format, this.localeId);
946
+ if (monthByChar) {
947
+ parsedDate = this.intl.parseDate(prefix + monthByChar + suffix, this.format, this.localeId);
909
948
  if (parsedDate) {
910
949
  this._value = parsedDate;
911
950
  this.setExisting(symbol, true);
@@ -952,11 +991,12 @@ export class DateObject {
952
991
  datePartValue = symbol === "M" ?
953
992
  parsedValue - JS_MONTH_OFFSET :
954
993
  parsedValue;
994
+ const isYear = symbol === "y";
955
995
  const isMonth = symbol === "M";
956
996
  const isDay = symbol === "d";
957
997
  let newValue = cloneDate(this._value);
958
998
  const invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
959
- const year = invalidDateParts.y.value || newValue.getFullYear();
999
+ const year = isYear ? datePartValue : invalidDateParts.y.value || newValue.getFullYear();
960
1000
  /* tslint:disable:no-shadowed-variable */
961
1001
  const month = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
962
1002
  /* tslint:enable:no-shadowed-variable */
@@ -967,8 +1007,8 @@ export class DateObject {
967
1007
  const milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
968
1008
  const dateCandidate = createDate(year, month, day, hour, minutes, seconds, milliseconds);
969
1009
  const dateCandidateExists = areDatePartsEqualTo(dateCandidate, year, month, day, hour, minutes, seconds, milliseconds);
970
- const newValueCandidate = isMonth || isDay ?
971
- this.modifyDateSymbolWithValue(newValue, symbol, isMonth ? month : day) :
1010
+ const newValueCandidate = isYear || isMonth || isDay ?
1011
+ this.modifyDateSymbolWithValue(newValue, symbol, isYear ? year : isMonth ? month : day) :
972
1012
  null;
973
1013
  let invalidDateFound = false;
974
1014
  if (isMonth && newValueCandidate) {
@@ -1053,6 +1093,46 @@ export class DateObject {
1053
1093
  this.setExisting(symbol, false);
1054
1094
  }
1055
1095
  }
1096
+ else if (isYear && newValueCandidate) {
1097
+ if (newValueCandidate.getFullYear() === year) {
1098
+ if (this.getExisting("d") && this.getExisting("M")) {
1099
+ if (dateCandidateExists) {
1100
+ newValue = cloneDate(dateCandidate);
1101
+ this.resetInvalidDateSymbol(symbol);
1102
+ }
1103
+ else {
1104
+ invalidDateFound = true;
1105
+ this.setInvalidDatePart(symbol, {
1106
+ value: year,
1107
+ date: cloneDate(newValueCandidate),
1108
+ startDate: cloneDate(this.value)
1109
+ });
1110
+ this.setExisting(symbol, false);
1111
+ }
1112
+ }
1113
+ else if (dateCandidateExists) {
1114
+ this.resetInvalidDateSymbol(symbol);
1115
+ newValue = cloneDate(dateCandidate);
1116
+ if (this.getExisting("M") && this.getExisting("d")) {
1117
+ this.setExisting("y", true);
1118
+ this.resetInvalidDateSymbol("y");
1119
+ }
1120
+ }
1121
+ else {
1122
+ this.resetInvalidDateSymbol(symbol);
1123
+ newValue = cloneDate(newValueCandidate);
1124
+ }
1125
+ }
1126
+ else {
1127
+ invalidDateFound = true;
1128
+ this.setInvalidDatePart(symbol, {
1129
+ value: year,
1130
+ date: cloneDate(newValueCandidate),
1131
+ startDate: cloneDate(this.value)
1132
+ });
1133
+ this.setExisting(symbol, false);
1134
+ }
1135
+ }
1056
1136
  if (!invalidDateFound) {
1057
1137
  this.setExisting(symbol, true);
1058
1138
  if (isInCaretMode && !isValidDate(parsedDate)) {
@@ -164,7 +164,6 @@ var DateObject = /** @class */ (function () {
164
164
  // and a month that has 31 days
165
165
  // so that the default date can accommodate maximum date values
166
166
  // it is better to use a fixed date instead of new Date()
167
- // as otherwise the
168
167
  return (0, kendo_date_math_1.createDate)(DEFAULT_LEAP_YEAR, 0, 31);
169
168
  };
170
169
  /**
@@ -674,10 +673,28 @@ var DateObject = /** @class */ (function () {
674
673
  var segmentLength = datePartEndIndex - datePartStartIndex + 1;
675
674
  var formatToTextLengthDiff = originalFormat.length - rawInputValue.length;
676
675
  if (isInCaretMode || (!isInCaretMode && !this.autoCorrectParts)) {
676
+ var segmentCharIndex = 0;
677
677
  for (var i = 0; i < baseDate.length; i++) {
678
678
  if (baseFormat[i] === symbol) {
679
679
  var existing = this.getExisting(symbol);
680
- current += existing ? baseDate[i] : '0';
680
+ if (symbol === "y") {
681
+ if (!this.hasInvalidDatePart() && this.getExisting("y")) {
682
+ current += baseDate[i];
683
+ }
684
+ else {
685
+ var invalidDatePartValue = this.getInvalidDatePartValue(symbol);
686
+ if ((0, utils_2.isPresent)(invalidDatePartValue)) {
687
+ current += (invalidDatePartValue || "").toString()[segmentCharIndex] || "";
688
+ segmentCharIndex++;
689
+ }
690
+ else {
691
+ current += existing ? baseDate[i] : '0';
692
+ }
693
+ }
694
+ }
695
+ else {
696
+ current += existing ? baseDate[i] : '0';
697
+ }
681
698
  if (formatToTextLengthDiff > 0) {
682
699
  if (datePartText.length + formatToTextLengthDiff < segmentLength) {
683
700
  datePartText += rawInputValue[i] || "";
@@ -714,10 +731,28 @@ var DateObject = /** @class */ (function () {
714
731
  prefix = "";
715
732
  suffix = "";
716
733
  replaced = false;
734
+ var segmentCharIndex_1 = 0;
717
735
  for (var i = 0; i < originalFormat.length; i++) {
718
736
  if (originalFormat[i] === symbol) {
719
737
  var existing = this.getExisting(symbol);
720
- current += existing ? baseDate[i] || "" : '0';
738
+ if (symbol === "y") {
739
+ if (!this.hasInvalidDatePart() && this.getExisting("y")) {
740
+ current += baseDate[i];
741
+ }
742
+ else {
743
+ var invalidDatePartValue = this.getInvalidDatePartValue(symbol);
744
+ if ((0, utils_2.isPresent)(invalidDatePartValue)) {
745
+ current += (invalidDatePartValue || "").toString()[segmentCharIndex_1] || "";
746
+ segmentCharIndex_1++;
747
+ }
748
+ else {
749
+ current += existing ? baseDate[i] : '0';
750
+ }
751
+ }
752
+ }
753
+ else {
754
+ current += existing ? baseDate[i] || "" : '0';
755
+ }
721
756
  if (formatToTextLengthDiff > 0) {
722
757
  if (datePartText.length + formatToTextLengthDiff < segmentLength) {
723
758
  datePartText += rawInputValue[i] || "";
@@ -766,7 +801,7 @@ var DateObject = /** @class */ (function () {
766
801
  }
767
802
  }
768
803
  var parsedDate = null;
769
- var month = this.matchMonth(currentChar);
804
+ var monthByChar = this.matchMonth(currentChar);
770
805
  var dayPeriod = this.matchDayPeriod(currentChar, symbol);
771
806
  var isZeroCurrentChar = currentChar === '0';
772
807
  var leadingZero = this.leadingZero || {};
@@ -840,7 +875,7 @@ var DateObject = /** @class */ (function () {
840
875
  }
841
876
  var isCurrentCharParsable = !isNaN(parseInt(currentChar, 10)) || (isInCaretMode && isDeleting && currentChar === "");
842
877
  if (!parsedDate && !isNaN(middleNumber) && isCurrentCharParsable && this.autoCorrectParts) {
843
- if (symbol === MONTH_SYMBOL && !month) {
878
+ if (symbol === MONTH_SYMBOL && !monthByChar) {
844
879
  // JS months start from 0 (January) instead of 1 (January)
845
880
  var monthNumber = middleNumber - JS_MONTH_OFFSET;
846
881
  if (monthNumber > -1 && monthNumber < 12) {
@@ -899,6 +934,10 @@ var DateObject = /** @class */ (function () {
899
934
  this.resetInvalidDateSymbol("M");
900
935
  }
901
936
  }
937
+ else if (symbol === "y") {
938
+ // if the parsed date is valid, make the whole value valid
939
+ this.markDatePartsAsExisting();
940
+ }
902
941
  if (!this.hasInvalidDatePart()) {
903
942
  this.markDatePartsAsExisting();
904
943
  if (!peekResult.peekedDate && peekResult.switchToNext && !this.autoCorrectParts) {
@@ -921,8 +960,8 @@ var DateObject = /** @class */ (function () {
921
960
  return (0, utils_2.extend)(parseResult, { value: this.value, switchToNext: switchToNext });
922
961
  }
923
962
  }
924
- if (month) {
925
- parsedDate = this.intl.parseDate(prefix + month + suffix, this.format, this.localeId);
963
+ if (monthByChar) {
964
+ parsedDate = this.intl.parseDate(prefix + monthByChar + suffix, this.format, this.localeId);
926
965
  if (parsedDate) {
927
966
  this._value = parsedDate;
928
967
  this.setExisting(symbol, true);
@@ -969,27 +1008,28 @@ var DateObject = /** @class */ (function () {
969
1008
  datePartValue = symbol === "M" ?
970
1009
  parsedValue - JS_MONTH_OFFSET :
971
1010
  parsedValue;
1011
+ var isYear = symbol === "y";
972
1012
  var isMonth = symbol === "M";
973
1013
  var isDay = symbol === "d";
974
1014
  var newValue = (0, kendo_date_math_1.cloneDate)(this._value);
975
1015
  var invalidDateParts = this._partiallyInvalidDate.invalidDateParts || {};
976
- var year = invalidDateParts.y.value || newValue.getFullYear();
1016
+ var year = isYear ? datePartValue : invalidDateParts.y.value || newValue.getFullYear();
977
1017
  /* tslint:disable:no-shadowed-variable */
978
- var month_1 = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
1018
+ var month = isMonth ? datePartValue : invalidDateParts.M.value || newValue.getMonth();
979
1019
  /* tslint:enable:no-shadowed-variable */
980
1020
  var day = isDay ? datePartValue : invalidDateParts.d.value || invalidDateParts.E.value || newValue.getDate();
981
1021
  var hour = invalidDateParts.h.value || invalidDateParts.H.value || newValue.getHours();
982
1022
  var minutes = invalidDateParts.m.value || newValue.getMinutes();
983
1023
  var seconds = invalidDateParts.s.value || newValue.getSeconds();
984
1024
  var milliseconds = invalidDateParts.S.value || newValue.getMilliseconds();
985
- var dateCandidate = (0, kendo_date_math_1.createDate)(year, month_1, day, hour, minutes, seconds, milliseconds);
986
- var dateCandidateExists = (0, utils_2.areDatePartsEqualTo)(dateCandidate, year, month_1, day, hour, minutes, seconds, milliseconds);
987
- var newValueCandidate = isMonth || isDay ?
988
- this.modifyDateSymbolWithValue(newValue, symbol, isMonth ? month_1 : day) :
1025
+ var dateCandidate = (0, kendo_date_math_1.createDate)(year, month, day, hour, minutes, seconds, milliseconds);
1026
+ var dateCandidateExists = (0, utils_2.areDatePartsEqualTo)(dateCandidate, year, month, day, hour, minutes, seconds, milliseconds);
1027
+ var newValueCandidate = isYear || isMonth || isDay ?
1028
+ this.modifyDateSymbolWithValue(newValue, symbol, isYear ? year : isMonth ? month : day) :
989
1029
  null;
990
1030
  var invalidDateFound = false;
991
1031
  if (isMonth && newValueCandidate) {
992
- if (newValueCandidate.getMonth() === month_1) {
1032
+ if (newValueCandidate.getMonth() === month) {
993
1033
  if (this.getExisting("d")) {
994
1034
  if (dateCandidateExists) {
995
1035
  newValue = (0, kendo_date_math_1.cloneDate)(dateCandidate);
@@ -998,7 +1038,7 @@ var DateObject = /** @class */ (function () {
998
1038
  else {
999
1039
  invalidDateFound = true;
1000
1040
  this.setInvalidDatePart(symbol, {
1001
- value: month_1,
1041
+ value: month,
1002
1042
  date: (0, kendo_date_math_1.cloneDate)(newValueCandidate),
1003
1043
  startDate: (0, kendo_date_math_1.cloneDate)(this.value)
1004
1044
  });
@@ -1022,7 +1062,7 @@ var DateObject = /** @class */ (function () {
1022
1062
  else {
1023
1063
  invalidDateFound = true;
1024
1064
  this.setInvalidDatePart(symbol, {
1025
- value: month_1,
1065
+ value: month,
1026
1066
  date: (0, kendo_date_math_1.cloneDate)(newValueCandidate),
1027
1067
  startDate: (0, kendo_date_math_1.cloneDate)(this.value)
1028
1068
  });
@@ -1070,6 +1110,46 @@ var DateObject = /** @class */ (function () {
1070
1110
  this.setExisting(symbol, false);
1071
1111
  }
1072
1112
  }
1113
+ else if (isYear && newValueCandidate) {
1114
+ if (newValueCandidate.getFullYear() === year) {
1115
+ if (this.getExisting("d") && this.getExisting("M")) {
1116
+ if (dateCandidateExists) {
1117
+ newValue = (0, kendo_date_math_1.cloneDate)(dateCandidate);
1118
+ this.resetInvalidDateSymbol(symbol);
1119
+ }
1120
+ else {
1121
+ invalidDateFound = true;
1122
+ this.setInvalidDatePart(symbol, {
1123
+ value: year,
1124
+ date: (0, kendo_date_math_1.cloneDate)(newValueCandidate),
1125
+ startDate: (0, kendo_date_math_1.cloneDate)(this.value)
1126
+ });
1127
+ this.setExisting(symbol, false);
1128
+ }
1129
+ }
1130
+ else if (dateCandidateExists) {
1131
+ this.resetInvalidDateSymbol(symbol);
1132
+ newValue = (0, kendo_date_math_1.cloneDate)(dateCandidate);
1133
+ if (this.getExisting("M") && this.getExisting("d")) {
1134
+ this.setExisting("y", true);
1135
+ this.resetInvalidDateSymbol("y");
1136
+ }
1137
+ }
1138
+ else {
1139
+ this.resetInvalidDateSymbol(symbol);
1140
+ newValue = (0, kendo_date_math_1.cloneDate)(newValueCandidate);
1141
+ }
1142
+ }
1143
+ else {
1144
+ invalidDateFound = true;
1145
+ this.setInvalidDatePart(symbol, {
1146
+ value: year,
1147
+ date: (0, kendo_date_math_1.cloneDate)(newValueCandidate),
1148
+ startDate: (0, kendo_date_math_1.cloneDate)(this.value)
1149
+ });
1150
+ this.setExisting(symbol, false);
1151
+ }
1152
+ }
1073
1153
  if (!invalidDateFound) {
1074
1154
  this.setExisting(symbol, true);
1075
1155
  if (isInCaretMode && !(0, utils_2.isValidDate)(parsedDate)) {