@momo-kits/date-picker 0.73.3-beta.5 → 0.74.2-react-native.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.
- package/WheelPicker.tsx +207 -0
- package/index.tsx +148 -0
- package/package.json +11 -10
- package/publish.sh +1 -2
- package/styles.ts +34 -0
- package/types.ts +88 -0
- package/utils.ts +112 -0
- package/datePicker/DatePicker.js +0 -770
- package/datePicker/DatePickerInput.js +0 -136
- package/datePicker/ListPicker.js +0 -208
- package/datePicker/WheelPicker.js +0 -328
- package/datePicker/custom/ScrollCustom.js +0 -60
- package/datePicker/helper/DatePickerHelper.js +0 -241
- package/index.js +0 -9
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
ScrollView
|
|
4
|
-
} from 'react-native';
|
|
5
|
-
|
|
6
|
-
class ScrollCustom extends Component {
|
|
7
|
-
constructor(props) {
|
|
8
|
-
super(props);
|
|
9
|
-
const { scrollEnabled } = this.props;
|
|
10
|
-
this.scrollEnabled = scrollEnabled;
|
|
11
|
-
this.state = {
|
|
12
|
-
scrollEnabled: this.scrollEnabled
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
scrollTo(event) {
|
|
17
|
-
if (event && this.ScrollView && this.ScrollView.scrollTo) {
|
|
18
|
-
this.ScrollView.scrollTo(event);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
setScrollEnabled(enable) {
|
|
23
|
-
const { scrollEnabled } = this.state;
|
|
24
|
-
if (enable !== scrollEnabled) {
|
|
25
|
-
this.setState({
|
|
26
|
-
scrollEnabled: enable
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
render() {
|
|
32
|
-
const { children } = this.props;
|
|
33
|
-
const { scrollEnabled } = this.state;
|
|
34
|
-
return (
|
|
35
|
-
<ScrollView
|
|
36
|
-
ref={(refName) => {
|
|
37
|
-
this.ScrollView = refName;
|
|
38
|
-
}}
|
|
39
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
40
|
-
{...this.props}
|
|
41
|
-
scrollEnabled={scrollEnabled}
|
|
42
|
-
>
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
children
|
|
46
|
-
}
|
|
47
|
-
</ScrollView>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
ScrollCustom.defaultProps = {
|
|
53
|
-
removeClippedSubviews: false,
|
|
54
|
-
showsHorizontalScrollIndicator: false,
|
|
55
|
-
showsVerticalScrollIndicator: false,
|
|
56
|
-
scrollEventThrottle: 16,
|
|
57
|
-
scrollEnabled: true
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
module.exports = ScrollCustom;
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/* eslint-disable prefer-template */
|
|
2
|
-
/* eslint-disable no-param-reassign */
|
|
3
|
-
export default class DatePickerHelper {
|
|
4
|
-
static arrayRange = [
|
|
5
|
-
'00:00',
|
|
6
|
-
'00:30',
|
|
7
|
-
'01:00',
|
|
8
|
-
'01:30',
|
|
9
|
-
'02:00',
|
|
10
|
-
'02:30',
|
|
11
|
-
'03:00',
|
|
12
|
-
'03:30',
|
|
13
|
-
'04:00',
|
|
14
|
-
'04:30',
|
|
15
|
-
'05:00',
|
|
16
|
-
'05:30',
|
|
17
|
-
'06:00',
|
|
18
|
-
'06:30',
|
|
19
|
-
'07:00',
|
|
20
|
-
'07:30',
|
|
21
|
-
'08:00',
|
|
22
|
-
'08:30',
|
|
23
|
-
'09:00',
|
|
24
|
-
'09:30',
|
|
25
|
-
'10:00',
|
|
26
|
-
'10:30',
|
|
27
|
-
'11:00',
|
|
28
|
-
'11:30',
|
|
29
|
-
'12:00',
|
|
30
|
-
'12:30',
|
|
31
|
-
'13:00',
|
|
32
|
-
'13:30',
|
|
33
|
-
'14:00',
|
|
34
|
-
'14:30',
|
|
35
|
-
'15:00',
|
|
36
|
-
'15:30',
|
|
37
|
-
'16:00',
|
|
38
|
-
'16:30',
|
|
39
|
-
'17:00',
|
|
40
|
-
'17:30',
|
|
41
|
-
'18:00',
|
|
42
|
-
'18:30',
|
|
43
|
-
'19:00',
|
|
44
|
-
'19:30',
|
|
45
|
-
'20:00',
|
|
46
|
-
'20:30',
|
|
47
|
-
'21:00',
|
|
48
|
-
'21:30',
|
|
49
|
-
'22:00',
|
|
50
|
-
'22:30',
|
|
51
|
-
'23:00',
|
|
52
|
-
'23:30',
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
static makeRange(min, max, isDouble) {
|
|
56
|
-
const array = [];
|
|
57
|
-
// eslint-disable-next-line no-plusplus
|
|
58
|
-
for (let i = min; i <= max; i++) {
|
|
59
|
-
const string = String(i);
|
|
60
|
-
const value =
|
|
61
|
-
string.length === 1 && isDouble ? `0${string}` : string;
|
|
62
|
-
array.push(value);
|
|
63
|
-
}
|
|
64
|
-
return array;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
static getCurrentDate(format) {
|
|
68
|
-
if (format) {
|
|
69
|
-
const current = new Date();
|
|
70
|
-
const day = current.getDate().toString();
|
|
71
|
-
const month = (current.getMonth() + 1).toString();
|
|
72
|
-
const year = current.getFullYear().toString();
|
|
73
|
-
return DatePickerHelper.toString(
|
|
74
|
-
day,
|
|
75
|
-
month,
|
|
76
|
-
year,
|
|
77
|
-
null,
|
|
78
|
-
null,
|
|
79
|
-
format,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
return '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
static formatDate(date, format) {
|
|
86
|
-
if (date && format) {
|
|
87
|
-
const {
|
|
88
|
-
year,
|
|
89
|
-
month,
|
|
90
|
-
day,
|
|
91
|
-
hour,
|
|
92
|
-
minute,
|
|
93
|
-
second = 0,
|
|
94
|
-
} = DatePickerHelper.getDateTimeFromFormat(date, format);
|
|
95
|
-
if (
|
|
96
|
-
DatePickerHelper.checkValidDate(year, month, day) &&
|
|
97
|
-
DatePickerHelper.checkValidTime(hour, minute, second)
|
|
98
|
-
) {
|
|
99
|
-
return new Date(year, month, day, hour, minute, second);
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static getDateTimeFromFormat(date, format) {
|
|
107
|
-
if (date == null || format == null) {
|
|
108
|
-
return {
|
|
109
|
-
year: null,
|
|
110
|
-
month: null,
|
|
111
|
-
day: null,
|
|
112
|
-
hour: null,
|
|
113
|
-
minute: null,
|
|
114
|
-
second: null,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if (typeof date !== 'string') {
|
|
118
|
-
date = date.toString();
|
|
119
|
-
}
|
|
120
|
-
if (typeof format !== 'string') {
|
|
121
|
-
format = format.toString();
|
|
122
|
-
}
|
|
123
|
-
const normalized = date.replace(/[^a-zA-Z0-9]/g, '-');
|
|
124
|
-
const normalizedFormat = format.replace(/[^a-zA-Z0-9]/g, '-');
|
|
125
|
-
const formatItems = normalizedFormat.split('-');
|
|
126
|
-
const dateItems = normalized.split('-');
|
|
127
|
-
|
|
128
|
-
const monthIndex = formatItems.indexOf('MM');
|
|
129
|
-
const dayIndex = formatItems.indexOf('dd');
|
|
130
|
-
const yearIndex = formatItems.indexOf('YYYY');
|
|
131
|
-
const hourIndex = formatItems.indexOf('hh');
|
|
132
|
-
const minutesIndex = formatItems.indexOf('mm');
|
|
133
|
-
const secondsIndex = formatItems.indexOf('ss');
|
|
134
|
-
|
|
135
|
-
const today = new Date();
|
|
136
|
-
|
|
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;
|
|
145
|
-
const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
|
|
146
|
-
|
|
147
|
-
const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
|
|
148
|
-
const minute = minutesIndex > -1 ? dateItems[minutesIndex] : 0;
|
|
149
|
-
const second = secondsIndex > -1 ? dateItems[secondsIndex] : 0;
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
year: year || null,
|
|
153
|
-
month: month >= 0 ? month : null,
|
|
154
|
-
day: day || null,
|
|
155
|
-
hour: hour || null,
|
|
156
|
-
minute: minute || null,
|
|
157
|
-
second: second || null,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
static round = (number) => {
|
|
162
|
-
if (parseInt(number) > 9) {
|
|
163
|
-
return number;
|
|
164
|
-
}
|
|
165
|
-
return `0${number}`;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
static toString(day, month, year, hour, minute, format) {
|
|
169
|
-
if (day && month && year && format) {
|
|
170
|
-
format = format.replace('YYYY', year);
|
|
171
|
-
format = format.replace('MM', this.round(month));
|
|
172
|
-
format = format.replace('dd', this.round(day));
|
|
173
|
-
format = format.replace('hh', hour);
|
|
174
|
-
format = format.replace('mm', minute);
|
|
175
|
-
return format;
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
|
|
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;
|
|
188
|
-
if (year != null && month != null && day != null) {
|
|
189
|
-
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);
|
|
196
|
-
return isDayValid && isMonthValid;
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
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
|
-
) {
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
static calculateDateSinceYearAgo(yearAgo) {
|
|
216
|
-
let nowDate = new Date();
|
|
217
|
-
nowDate = new Date(
|
|
218
|
-
nowDate.getFullYear() - yearAgo,
|
|
219
|
-
nowDate.getMonth(),
|
|
220
|
-
nowDate.getDate(),
|
|
221
|
-
);
|
|
222
|
-
return nowDate;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
static getMaxDate(
|
|
226
|
-
month = new Date().getMonth(),
|
|
227
|
-
year = new Date().getFullYear(),
|
|
228
|
-
) {
|
|
229
|
-
const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
230
|
-
// Adjust for leap years
|
|
231
|
-
if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
|
|
232
|
-
monthLength[1] = 29;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return monthLength[month - 1];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
static capitalizeFirstLetter(string) {
|
|
239
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
240
|
-
}
|
|
241
|
-
}
|