@momo-kits/date-picker 0.0.74-beta → 0.72.1
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.
- package/datePicker/DatePicker.js +709 -543
- package/datePicker/DatePickerInput.js +118 -90
- package/datePicker/ListPicker.js +186 -171
- package/datePicker/WheelPicker.js +288 -260
- package/datePicker/helper/DatePickerHelper.js +65 -21
- package/package.json +14 -14
- package/publish.sh +2 -2
|
@@ -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,7 +57,8 @@ 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 =
|
|
60
|
+
const value =
|
|
61
|
+
string.length === 1 && isDouble ? `0${string}` : string;
|
|
61
62
|
array.push(value);
|
|
62
63
|
}
|
|
63
64
|
return array;
|
|
@@ -69,7 +70,14 @@ export default class DatePickerHelper {
|
|
|
69
70
|
const day = current.getDate().toString();
|
|
70
71
|
const month = (current.getMonth() + 1).toString();
|
|
71
72
|
const year = current.getFullYear().toString();
|
|
72
|
-
return DatePickerHelper.toString(
|
|
73
|
+
return DatePickerHelper.toString(
|
|
74
|
+
day,
|
|
75
|
+
month,
|
|
76
|
+
year,
|
|
77
|
+
null,
|
|
78
|
+
null,
|
|
79
|
+
format,
|
|
80
|
+
);
|
|
73
81
|
}
|
|
74
82
|
return '';
|
|
75
83
|
}
|
|
@@ -77,10 +85,17 @@ export default class DatePickerHelper {
|
|
|
77
85
|
static formatDate(date, format) {
|
|
78
86
|
if (date && format) {
|
|
79
87
|
const {
|
|
80
|
-
year,
|
|
88
|
+
year,
|
|
89
|
+
month,
|
|
90
|
+
day,
|
|
91
|
+
hour,
|
|
92
|
+
minute,
|
|
93
|
+
second = 0,
|
|
81
94
|
} = DatePickerHelper.getDateTimeFromFormat(date, format);
|
|
82
|
-
if (
|
|
83
|
-
|
|
95
|
+
if (
|
|
96
|
+
DatePickerHelper.checkValidDate(year, month, day) &&
|
|
97
|
+
DatePickerHelper.checkValidTime(hour, minute, second)
|
|
98
|
+
) {
|
|
84
99
|
return new Date(year, month, day, hour, minute, second);
|
|
85
100
|
}
|
|
86
101
|
return null;
|
|
@@ -119,8 +134,14 @@ export default class DatePickerHelper {
|
|
|
119
134
|
|
|
120
135
|
const today = new Date();
|
|
121
136
|
|
|
122
|
-
const year =
|
|
123
|
-
|
|
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;
|
|
124
145
|
const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
|
|
125
146
|
|
|
126
147
|
const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
|
|
@@ -142,7 +163,7 @@ export default class DatePickerHelper {
|
|
|
142
163
|
return number;
|
|
143
164
|
}
|
|
144
165
|
return `0${number}`;
|
|
145
|
-
}
|
|
166
|
+
};
|
|
146
167
|
|
|
147
168
|
static toString(day, month, year, hour, minute, format) {
|
|
148
169
|
if (day && month && year && format) {
|
|
@@ -156,24 +177,36 @@ export default class DatePickerHelper {
|
|
|
156
177
|
return null;
|
|
157
178
|
}
|
|
158
179
|
|
|
159
|
-
static checkValidDate(
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
180
|
+
static checkValidDate(y, m, d) {
|
|
181
|
+
const year = parseInt(y);
|
|
182
|
+
const month = parseInt(m);
|
|
183
|
+
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;
|
|
164
188
|
if (year != null && month != null && day != null) {
|
|
165
189
|
const isDayValid = day > 0;
|
|
166
|
-
const isMonthValid =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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);
|
|
170
196
|
return isDayValid && isMonthValid;
|
|
171
197
|
}
|
|
172
198
|
return false;
|
|
173
199
|
}
|
|
174
200
|
|
|
175
201
|
static checkValidTime(hour, minute, second) {
|
|
176
|
-
if (
|
|
202
|
+
if (
|
|
203
|
+
hour >= 0 &&
|
|
204
|
+
hour < 24 &&
|
|
205
|
+
minute >= 0 &&
|
|
206
|
+
minute < 60 &&
|
|
207
|
+
second >= 0 &&
|
|
208
|
+
second < 60
|
|
209
|
+
) {
|
|
177
210
|
return true;
|
|
178
211
|
}
|
|
179
212
|
return false;
|
|
@@ -181,11 +214,18 @@ export default class DatePickerHelper {
|
|
|
181
214
|
|
|
182
215
|
static calculateDateSinceYearAgo(yearAgo) {
|
|
183
216
|
let nowDate = new Date();
|
|
184
|
-
nowDate = new Date(
|
|
217
|
+
nowDate = new Date(
|
|
218
|
+
nowDate.getFullYear() - yearAgo,
|
|
219
|
+
nowDate.getMonth(),
|
|
220
|
+
nowDate.getDate(),
|
|
221
|
+
);
|
|
185
222
|
return nowDate;
|
|
186
223
|
}
|
|
187
224
|
|
|
188
|
-
static getMaxDate(
|
|
225
|
+
static getMaxDate(
|
|
226
|
+
month = new Date().getMonth(),
|
|
227
|
+
year = new Date().getFullYear(),
|
|
228
|
+
) {
|
|
189
229
|
const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
190
230
|
// Adjust for leap years
|
|
191
231
|
if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
|
|
@@ -194,4 +234,8 @@ export default class DatePickerHelper {
|
|
|
194
234
|
|
|
195
235
|
return monthLength[month - 1];
|
|
196
236
|
}
|
|
237
|
+
|
|
238
|
+
static capitalizeFirstLetter(string) {
|
|
239
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
240
|
+
}
|
|
197
241
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@momo-kits/date-picker",
|
|
3
|
+
"version": "0.72.1",
|
|
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
16
|
}
|
package/publish.sh
CHANGED
|
@@ -21,9 +21,9 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
|
|
|
21
21
|
#npm login
|
|
22
22
|
#publish dist to npm
|
|
23
23
|
cd dist
|
|
24
|
-
npm publish --access=public
|
|
24
|
+
npm publish --tag beta --access=public
|
|
25
25
|
cd ..
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/date-picker new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/date-picker"}'
|
|
29
|
+
#curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/date-picker new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/date-picker"}'
|