nexheal-lib 0.0.16 → 0.0.17

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.
@@ -723,7 +723,7 @@ class CalendarControl {
723
723
  if (m) {
724
724
  // 24h
725
725
  const h = +m[1], min = +m[2];
726
- if (h < 24 && min < 60) {
726
+ if (h < 24 && min < 60 && this.isTimeValid(h, min)) {
727
727
  this.selectedHour = h;
728
728
  this.selectedMinute = min;
729
729
  }
@@ -740,8 +740,13 @@ class CalendarControl {
740
740
  h += 12;
741
741
  if (ap === "AM" && h === 12)
742
742
  h = 0;
743
- this.selectedHour = h;
744
- this.selectedMinute = min;
743
+ if (this.isTimeValid(h, min)) {
744
+ this.selectedHour = h;
745
+ this.selectedMinute = min;
746
+ }
747
+ else {
748
+ return this.clearDate(new Event("manual"));
749
+ }
745
750
  }
746
751
  else {
747
752
  return this.clearDate(new Event("manual"));
@@ -1016,44 +1021,110 @@ class CalendarControl {
1016
1021
  setMeridian(value) {
1017
1022
  if (this.meridian === value)
1018
1023
  return;
1024
+ let nextHour = this.selectedHour;
1019
1025
  if (value === "AM" && this.selectedHour >= 12) {
1020
- this.selectedHour -= 12;
1026
+ nextHour -= 12;
1021
1027
  }
1022
1028
  else if (value === "PM" && this.selectedHour < 12) {
1023
- this.selectedHour += 12;
1029
+ nextHour += 12;
1030
+ }
1031
+ if (this.isTimeValid(nextHour, this.selectedMinute)) {
1032
+ this.selectedHour = nextHour;
1033
+ this.patchDateWithTime();
1024
1034
  }
1025
- this.patchDateWithTime();
1026
1035
  }
1027
1036
  buildDateWithTime(day) {
1028
1037
  return new Date(this.displayYear, this.displayMonth, day, this.selectedHour, this.selectedMinute);
1029
1038
  }
1039
+ isTimeValid(hour, minute) {
1040
+ const testDate = new Date(this.selectedDate || new Date());
1041
+ testDate.setHours(hour, minute, 0, 0);
1042
+ if (this._minDate) {
1043
+ const min = new Date(this._minDate);
1044
+ if (this.timeOnly || this.showTime) {
1045
+ min.setFullYear(testDate.getFullYear(), testDate.getMonth(), testDate.getDate());
1046
+ }
1047
+ if (testDate < min)
1048
+ return false;
1049
+ }
1050
+ if (this._maxDate) {
1051
+ const max = new Date(this._maxDate);
1052
+ if (this.timeOnly || this.showTime) {
1053
+ max.setFullYear(testDate.getFullYear(), testDate.getMonth(), testDate.getDate());
1054
+ }
1055
+ if (testDate > max)
1056
+ return false;
1057
+ }
1058
+ return true;
1059
+ }
1030
1060
  incrementHour() {
1031
- this.selectedHour = (this.selectedHour + 1) % 24;
1032
- if (this.showTime || this.timeOnly)
1033
- this.patchDateWithTime();
1061
+ let nextHour = (this.selectedHour + 1) % 24;
1062
+ let found = false;
1063
+ for (let i = 0; i < 24; i++) {
1064
+ if (this.isTimeValid(nextHour, this.selectedMinute)) {
1065
+ found = true;
1066
+ break;
1067
+ }
1068
+ nextHour = (nextHour + 1) % 24;
1069
+ }
1070
+ if (found) {
1071
+ this.selectedHour = nextHour;
1072
+ if (this.showTime || this.timeOnly)
1073
+ this.patchDateWithTime();
1074
+ }
1034
1075
  }
1035
1076
  decrementHour() {
1036
- this.selectedHour = (this.selectedHour + 23) % 24;
1037
- if (this.showTime || this.timeOnly)
1038
- this.patchDateWithTime();
1077
+ let nextHour = (this.selectedHour + 23) % 24;
1078
+ let found = false;
1079
+ for (let i = 0; i < 24; i++) {
1080
+ if (this.isTimeValid(nextHour, this.selectedMinute)) {
1081
+ found = true;
1082
+ break;
1083
+ }
1084
+ nextHour = (nextHour + 23) % 24;
1085
+ }
1086
+ if (found) {
1087
+ this.selectedHour = nextHour;
1088
+ if (this.showTime || this.timeOnly)
1089
+ this.patchDateWithTime();
1090
+ }
1039
1091
  }
1040
1092
  incrementMinute() {
1041
- this.selectedMinute++;
1042
- if (this.selectedMinute >= 60) {
1043
- this.selectedMinute = 0;
1044
- this.selectedHour = (this.selectedHour + 1) % 24;
1093
+ let nextMin = this.selectedMinute + 1;
1094
+ let nextHour = this.selectedHour;
1095
+ if (nextMin >= 60) {
1096
+ nextMin = 0;
1097
+ nextHour = (nextHour + 1) % 24;
1098
+ }
1099
+ if (!this.isTimeValid(nextHour, nextMin)) {
1100
+ if (this._minDate) {
1101
+ const min = new Date(this._minDate);
1102
+ nextHour = min.getHours();
1103
+ nextMin = min.getMinutes();
1104
+ }
1045
1105
  }
1106
+ this.selectedHour = nextHour;
1107
+ this.selectedMinute = nextMin;
1046
1108
  if (this.showTime || this.timeOnly) {
1047
1109
  this.patchDateWithTime();
1048
1110
  }
1049
1111
  }
1050
1112
  decrementMinute() {
1051
- this.selectedMinute--;
1052
- if (this.selectedMinute < 0) {
1053
- this.selectedMinute = 59;
1054
- // go back an hour, wrapping 0 → 23
1055
- this.selectedHour = (this.selectedHour + 23) % 24;
1113
+ let nextMin = this.selectedMinute - 1;
1114
+ let nextHour = this.selectedHour;
1115
+ if (nextMin < 0) {
1116
+ nextMin = 59;
1117
+ nextHour = (nextHour + 23) % 24;
1118
+ }
1119
+ if (!this.isTimeValid(nextHour, nextMin)) {
1120
+ if (this._maxDate) {
1121
+ const max = new Date(this._maxDate);
1122
+ nextHour = max.getHours();
1123
+ nextMin = max.getMinutes();
1124
+ }
1056
1125
  }
1126
+ this.selectedHour = nextHour;
1127
+ this.selectedMinute = nextMin;
1057
1128
  if (this.showTime || this.timeOnly) {
1058
1129
  this.patchDateWithTime();
1059
1130
  }
@@ -1122,6 +1193,20 @@ class CalendarControl {
1122
1193
  this.displayMonth = now.getMonth();
1123
1194
  this.displayYear = now.getFullYear();
1124
1195
  }
1196
+ if (!this.inputControl.value && (this.timeOnly || this.showTime)) {
1197
+ if (this._minDate) {
1198
+ const min = new Date(this._minDate);
1199
+ this.selectedHour = min.getHours();
1200
+ this.selectedMinute = min.getMinutes();
1201
+ }
1202
+ else if (!this.isTimeValid(this.selectedHour, this.selectedMinute)) {
1203
+ if (this._maxDate) {
1204
+ const max = new Date(this._maxDate);
1205
+ this.selectedHour = max.getHours();
1206
+ this.selectedMinute = max.getMinutes();
1207
+ }
1208
+ }
1209
+ }
1125
1210
  // destroy any old popper
1126
1211
  if (this.popperInstance) {
1127
1212
  this.popperInstance.destroy();