@momo-kits/date-picker 0.0.19 → 0.0.24
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
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from 'react-native';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import {
|
|
9
|
-
BottomPopupHeader, Button, Text, ScreenUtils, SwitchLanguage, Spacing
|
|
9
|
+
BottomPopupHeader, Button, Text, ScreenUtils, SwitchLanguage, Spacing, Colors
|
|
10
10
|
} from '@momo-kits/core';
|
|
11
11
|
import WheelPicker from './WheelPicker';
|
|
12
12
|
import DatePickerHelper from './helper/DatePickerHelper';
|
|
@@ -26,13 +26,22 @@ const styles = StyleSheet.create({
|
|
|
26
26
|
width: widthScreen,
|
|
27
27
|
alignItems: 'center',
|
|
28
28
|
justifyContent: 'center',
|
|
29
|
+
paddingHorizontal: 21,
|
|
30
|
+
paddingTop: 12
|
|
29
31
|
},
|
|
30
32
|
column: {
|
|
31
33
|
borderWidth: 2,
|
|
32
34
|
borderColor: 'red',
|
|
33
35
|
},
|
|
34
36
|
header: {
|
|
35
|
-
|
|
37
|
+
borderTopLeftRadius: 12,
|
|
38
|
+
borderTopRightRadius: 12,
|
|
39
|
+
//backgroundColor:'red',
|
|
40
|
+
height: 64,
|
|
41
|
+
borderBottomColor: Colors.black_04,
|
|
42
|
+
borderBottomWidth: 1,
|
|
43
|
+
alignItems:'center',
|
|
44
|
+
justifyContent:'center',
|
|
36
45
|
marginBottom: 0, // Spacing.S,
|
|
37
46
|
},
|
|
38
47
|
view: {
|
|
@@ -171,15 +180,13 @@ class DatePicker extends Component {
|
|
|
171
180
|
current = this.maxDate;
|
|
172
181
|
}
|
|
173
182
|
if (format === 'hh:mm' && isRanged) {
|
|
174
|
-
const valueHours_1 = this.selectedDate ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '';
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
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
|
|
179
186
|
? this.ranged.indexOf(valueHours_1)
|
|
180
187
|
: this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
|
|
181
188
|
|
|
182
|
-
this.hourRangeIndex_2 =
|
|
189
|
+
this.hourRangeIndex_2 = valueHours_2
|
|
183
190
|
? this.ranged.indexOf(valueHours_2)
|
|
184
191
|
: this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
|
|
185
192
|
return;
|
|
@@ -261,7 +268,6 @@ class DatePicker extends Component {
|
|
|
261
268
|
const year = this.years[this.yearIndex];
|
|
262
269
|
const hour = this.hours[this.hourIndex];
|
|
263
270
|
const minute = this.minutes[this.minuteIndex];
|
|
264
|
-
|
|
265
271
|
const selectedDateFormatted = DatePickerHelper.toString(day, month, year, hour, minute, format);
|
|
266
272
|
|
|
267
273
|
if (onSelected && typeof onSelected === 'function') {
|
|
@@ -540,7 +546,7 @@ class DatePicker extends Component {
|
|
|
540
546
|
renderFooter() {
|
|
541
547
|
const { titleFooter, renderFooter } = this.props;
|
|
542
548
|
return renderFooter ? renderFooter() : (
|
|
543
|
-
<View style={{ paddingHorizontal: 12, marginBottom: ifIphoneX(
|
|
549
|
+
<View style={{ paddingHorizontal: 12, marginBottom: ifIphoneX(35, 12), marginTop: 16 }}>
|
|
544
550
|
<Button
|
|
545
551
|
onPress={this.finish}
|
|
546
552
|
title={titleFooter || SwitchLanguage.confirm}
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
LinearGradient, Text, Colors, ScaleSize
|
|
7
7
|
} from '@momo-kits/core';
|
|
8
8
|
import ScrollCustom from './custom/ScrollCustom';
|
|
9
|
+
import DatePickerHelper from './helper/DatePickerHelper';
|
|
9
10
|
|
|
10
11
|
const widthScreen = Dimensions.get('window').width;
|
|
11
12
|
// var heightScreen = Dimensions.get('window').height;
|
|
@@ -171,19 +172,20 @@ export default class WheelPicker extends Component {
|
|
|
171
172
|
const { items, value, width } = this.state;
|
|
172
173
|
const { preFix, bottomOffset } = this.props;
|
|
173
174
|
return (
|
|
174
|
-
<View style={{ flex: 1, height: heightContain +
|
|
175
|
-
<Text.SubTitle style={{
|
|
175
|
+
<View style={{ flex: 1, height: heightContain + 40 }}>
|
|
176
|
+
<Text.SubTitle weight='bold' style={{
|
|
176
177
|
color: Colors.black_17, marginLeft: 6, marginBottom: 3
|
|
177
178
|
}}
|
|
178
179
|
>
|
|
179
|
-
{preFix
|
|
180
|
+
{DatePickerHelper.capitalizeFirstLetter(preFix || '')}
|
|
180
181
|
</Text.SubTitle>
|
|
181
182
|
<View
|
|
182
183
|
style={{
|
|
183
184
|
flex: 1,
|
|
184
185
|
height: heightContain,
|
|
185
|
-
//
|
|
186
|
+
//backgroundColor: 'blue',
|
|
186
187
|
marginHorizontal: 6,
|
|
188
|
+
paddingBottom: 20,
|
|
187
189
|
borderWidth: 1,
|
|
188
190
|
borderColor: Colors.black_04,
|
|
189
191
|
borderRadius: 8,
|
|
@@ -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(
|
|
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)
|
|
167
|
-
|| (months30.indexOf(month)
|
|
168
|
-
|| (
|
|
169
|
-
|| (months28.indexOf(month)
|
|
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;
|
|
@@ -194,4 +198,8 @@ export default class DatePickerHelper {
|
|
|
194
198
|
|
|
195
199
|
return monthLength[month - 1];
|
|
196
200
|
}
|
|
201
|
+
|
|
202
|
+
static capitalizeFirstLetter(string) {
|
|
203
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
204
|
+
}
|
|
197
205
|
}
|