@momo-kits/date-picker 0.0.23-beta-1 → 0.0.23-beta-2

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.
@@ -180,15 +180,13 @@ class DatePicker extends Component {
180
180
  current = this.maxDate;
181
181
  }
182
182
  if (format === 'hh:mm' && isRanged) {
183
- const valueHours_1 = this.selectedDate ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '';
184
-
185
- const valueHours_2 = this.selectedDate ? `${getStrings(this.selectedDate?.to?.getHours()?.toString())}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}` : '';
186
-
187
- this.hourRangeIndex_1 = this.selectedDate
183
+ const valueHours_1 = this.selectedDate?.from ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '00:00';
184
+ const valueHours_2 = this.selectedDate?.to ? `${getStrings(this.selectedDate?.to?.getHours()?.toString())}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}` : '00:00';
185
+ this.hourRangeIndex_1 = valueHours_1
188
186
  ? this.ranged.indexOf(valueHours_1)
189
187
  : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
190
188
 
191
- this.hourRangeIndex_2 = this.selectedDate
189
+ this.hourRangeIndex_2 = valueHours_2
192
190
  ? this.ranged.indexOf(valueHours_2)
193
191
  : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
194
192
  return;
@@ -270,7 +268,6 @@ class DatePicker extends Component {
270
268
  const year = this.years[this.yearIndex];
271
269
  const hour = this.hours[this.hourIndex];
272
270
  const minute = this.minutes[this.minuteIndex];
273
-
274
271
  const selectedDateFormatted = DatePickerHelper.toString(day, month, year, hour, minute, format);
275
272
 
276
273
  if (onSelected && typeof onSelected === 'function') {
@@ -77,7 +77,7 @@ export default class DatePickerHelper {
77
77
  static formatDate(date, format) {
78
78
  if (date && format) {
79
79
  const {
80
- year, month, day, hour, minute, second
80
+ year, month, day, hour, minute, second = 0
81
81
  } = DatePickerHelper.getDateTimeFromFormat(date, format);
82
82
  if (DatePickerHelper.checkValidDate(year, month, day)
83
83
  && DatePickerHelper.checkValidTime(hour, minute, second)) {
@@ -156,17 +156,21 @@ export default class DatePickerHelper {
156
156
  return null;
157
157
  }
158
158
 
159
- static checkValidDate(year, month, day) {
159
+ static checkValidDate(y, m, d) {
160
+ const year = parseInt(y);
161
+ const month = parseInt(m);
162
+ const day = parseInt(d);
160
163
  const months31 = [0, 2, 4, 6, 7, 9, 11];
161
164
  const months30 = [3, 5, 8, 10];
162
165
  const months28 = [1];
163
166
  const isLeap = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
164
167
  if (year != null && month != null && day != null) {
165
168
  const isDayValid = day > 0;
166
- const isMonthValid = (months31.indexOf(month) !== -1 && day <= 31)
167
- || (months30.indexOf(month) !== -1 && day <= 30)
168
- || (months28.indexOf(month) !== -1 && day <= 28)
169
- || (months28.indexOf(month) !== -1 && day <= 29 && isLeap);
169
+ const isMonthValid = (months31.indexOf(parseInt(month)) != -1 && day <= 31)
170
+ || (months30.indexOf(month) != -1 && day <= 30)
171
+ || (months30.indexOf(month) != -1 && day <= 31)
172
+ || (months28.indexOf(month) != -1 && day <= 28)
173
+ || (months28.indexOf(month) != -1 && day <= 29 && isLeap);
170
174
  return isDayValid && isMonthValid;
171
175
  }
172
176
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/date-picker",
3
- "version": "0.0.23-beta-1",
3
+ "version": "0.0.23-beta-2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},