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

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;
@@ -208,7 +206,7 @@ class DatePicker extends Component {
208
206
  if (format === 'hh:mm' && !isRanged) {
209
207
  const valueHours = this.selectedDate ? this.selectedDate?.getHours()?.toString()?.length === 1 ? `0${this.selectedDate.getHours().toString()}` : this.selectedDate?.getHours()?.toString() || '' : '';
210
208
  const valueMinute = this.selectedDate ? this.selectedDate?.getMinutes()?.toString()?.length === 1 ? `0${this.selectedDate.getMinutes().toString()}` : this.selectedDate?.getMinutes()?.toString() || '' : '';
211
-
209
+
212
210
  this.hourIndex = this.selectedDate
213
211
  ? this.hours.indexOf(valueHours)
214
212
  : this.hours.indexOf(current.getHours().toString().length === 1 ? `0${current.getHours().toString()}` : current.getHours().toString());
@@ -268,11 +266,9 @@ class DatePicker extends Component {
268
266
  const day = this.days[this.dayIndex];
269
267
  const month = this.months[this.monthIndex];
270
268
  const year = this.years[this.yearIndex];
271
- const hour = this.hours[this.hourIndex];
272
- const minute = this.minutes[this.minuteIndex];
273
-
269
+ const hour = this.hours[this.hourIndex] || '00';
270
+ const minute = this.minutes[this.minuteIndex] || '00';
274
271
  const selectedDateFormatted = DatePickerHelper.toString(day, month, year, hour, minute, format);
275
-
276
272
  if (onSelected && typeof onSelected === 'function') {
277
273
  onSelected(selectedDateFormatted || selectedDate || DatePickerHelper.getCurrentDate(format));
278
274
  }
@@ -15,8 +15,9 @@ export default class WheelPicker extends Component {
15
15
  constructor(props) {
16
16
  super(props);
17
17
  const {
18
- heightItem, value, numberItem, arrayValue
18
+ heightItem, value: valueItem, numberItem, arrayValue
19
19
  } = this.props;
20
+ const value = valueItem === -1 ? 0 : valueItem;
20
21
  this.heightItem = heightItem;
21
22
  this.currentPosition = value * this.heightItem;
22
23
  this.prePosition = this.currentPosition;
@@ -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.25",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {},