@momo-kits/date-picker 0.0.65-beta.21 → 0.0.65-beta.23

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.
@@ -49,7 +49,7 @@ export default class DatePickerHelper {
49
49
  '22:00',
50
50
  '22:30',
51
51
  '23:00',
52
- '23:30',
52
+ '23:30'
53
53
  ];
54
54
 
55
55
  static makeRange(min, max, isDouble) {
@@ -57,8 +57,7 @@ export default class DatePickerHelper {
57
57
  // eslint-disable-next-line no-plusplus
58
58
  for (let i = min; i <= max; i++) {
59
59
  const string = String(i);
60
- const value =
61
- string.length === 1 && isDouble ? `0${string}` : string;
60
+ const value = string.length === 1 && isDouble ? `0${string}` : string;
62
61
  array.push(value);
63
62
  }
64
63
  return array;
@@ -70,14 +69,7 @@ export default class DatePickerHelper {
70
69
  const day = current.getDate().toString();
71
70
  const month = (current.getMonth() + 1).toString();
72
71
  const year = current.getFullYear().toString();
73
- return DatePickerHelper.toString(
74
- day,
75
- month,
76
- year,
77
- null,
78
- null,
79
- format,
80
- );
72
+ return DatePickerHelper.toString(day, month, year, null, null, format);
81
73
  }
82
74
  return '';
83
75
  }
@@ -85,17 +77,10 @@ export default class DatePickerHelper {
85
77
  static formatDate(date, format) {
86
78
  if (date && format) {
87
79
  const {
88
- year,
89
- month,
90
- day,
91
- hour,
92
- minute,
93
- second = 0,
80
+ year, month, day, hour, minute, second = 0
94
81
  } = DatePickerHelper.getDateTimeFromFormat(date, format);
95
- if (
96
- DatePickerHelper.checkValidDate(year, month, day) &&
97
- DatePickerHelper.checkValidTime(hour, minute, second)
98
- ) {
82
+ if (DatePickerHelper.checkValidDate(year, month, day)
83
+ && DatePickerHelper.checkValidTime(hour, minute, second)) {
99
84
  return new Date(year, month, day, hour, minute, second);
100
85
  }
101
86
  return null;
@@ -134,14 +119,8 @@ export default class DatePickerHelper {
134
119
 
135
120
  const today = new Date();
136
121
 
137
- const year =
138
- yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
139
- const month =
140
- monthIndex > -1
141
- ? dateItems?.[monthIndex] - 1
142
- : today.getMonth() === 0
143
- ? 1
144
- : today.getMonth() - 1;
122
+ const year = yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
123
+ const month = monthIndex > -1 ? dateItems?.[monthIndex] - 1 : today.getMonth() === 0 ? 1 : today.getMonth() - 1;
145
124
  const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
146
125
 
147
126
  const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
@@ -163,7 +142,7 @@ export default class DatePickerHelper {
163
142
  return number;
164
143
  }
165
144
  return `0${number}`;
166
- };
145
+ }
167
146
 
168
147
  static toString(day, month, year, hour, minute, format) {
169
148
  if (day && month && year && format) {
@@ -181,32 +160,24 @@ export default class DatePickerHelper {
181
160
  const year = parseInt(y);
182
161
  const month = parseInt(m);
183
162
  const day = parseInt(d);
184
- const months31 = [1, 3, 5, 7, 8, 10, 12];
185
- const months30 = [4, 6, 9, 11];
186
- const months28 = [2];
187
- const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
163
+ const months31 = [0, 2, 4, 6, 7, 9, 11];
164
+ const months30 = [3, 5, 8, 10];
165
+ const months28 = [1];
166
+ const isLeap = ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
188
167
  if (year != null && month != null && day != null) {
189
168
  const isDayValid = day > 0;
190
- const isMonthValid =
191
- (months31.indexOf(parseInt(month)) != -1 && day <= 31) ||
192
- (months30.indexOf(month) != -1 && day <= 30) ||
193
- (months30.indexOf(month) != -1 && day <= 31) ||
194
- (months28.indexOf(month) != -1 && day <= 28) ||
195
- (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);
196
174
  return isDayValid && isMonthValid;
197
175
  }
198
176
  return false;
199
177
  }
200
178
 
201
179
  static checkValidTime(hour, minute, second) {
202
- if (
203
- hour >= 0 &&
204
- hour < 24 &&
205
- minute >= 0 &&
206
- minute < 60 &&
207
- second >= 0 &&
208
- second < 60
209
- ) {
180
+ if ((hour >= 0 && hour < 24) && (minute >= 0 && minute < 60) && (second >= 0 && second < 60)) {
210
181
  return true;
211
182
  }
212
183
  return false;
@@ -214,18 +185,11 @@ export default class DatePickerHelper {
214
185
 
215
186
  static calculateDateSinceYearAgo(yearAgo) {
216
187
  let nowDate = new Date();
217
- nowDate = new Date(
218
- nowDate.getFullYear() - yearAgo,
219
- nowDate.getMonth(),
220
- nowDate.getDate(),
221
- );
188
+ nowDate = new Date(nowDate.getFullYear() - yearAgo, nowDate.getMonth(), nowDate.getDate());
222
189
  return nowDate;
223
190
  }
224
191
 
225
- static getMaxDate(
226
- month = new Date().getMonth(),
227
- year = new Date().getFullYear(),
228
- ) {
192
+ static getMaxDate(month = new Date().getMonth(), year = new Date().getFullYear()) {
229
193
  const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
230
194
  // Adjust for leap years
231
195
  if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
@@ -237,5 +201,5 @@ export default class DatePickerHelper {
237
201
 
238
202
  static capitalizeFirstLetter(string) {
239
203
  return string.charAt(0).toUpperCase() + string.slice(1);
240
- }
204
+ }
241
205
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
- "name": "@momo-kits/date-picker",
3
- "version": "0.0.65-beta.21",
4
- "private": false,
5
- "main": "index.js",
6
- "dependencies": {},
7
- "peerDependencies": {
8
- "@momo-kits/core-v2": ">=0.0.5-beta",
9
- "lodash": "^4.17.15",
10
- "prop-types": "^15.7.2",
11
- "react": "16.9.0",
12
- "react-native": ">=0.55"
13
- },
14
- "devDependencies": {},
15
- "license": "MoMo"
16
- }
2
+ "name": "@momo-kits/date-picker",
3
+ "version": "0.0.65-beta.23",
4
+ "private": false,
5
+ "main": "index.js",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "@momo-kits/core": ">=0.0.5-beta",
9
+ "lodash": "^4.17.15",
10
+ "prop-types": "^15.7.2",
11
+ "react": "16.9.0",
12
+ "react-native": ">=0.55"
13
+ },
14
+ "devDependencies": {},
15
+ "license": "MoMo"
16
+ }