Skip to content

Commit 3381063

Browse files
authored
Merge branch 'master' into master
2 parents b0eb48f + ec9fd7a commit 3381063

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
9494
| onPressMask | - | `function` | This is called when clicking the ios modal mask |
9595
| modalOnResponderTerminationRequest | - | `function` | Set the callback for React Native's [Gesture Responder System](https://facebook.github.io/react-native/docs/gesture-responder-system.html#responder-lifecycle)'s call to `onResponderTerminationRequest`. By default this will reject a termination request, but can be overidden in case the View under the Modal is implementing custom gesture responders, and you wish for those to be overidden in certain cases. |
9696
| TouchableComponent | `TouchableHighlight` | `Component` | Replace the `TouchableHighlight` with a custom `Component`. For example : `TouchableOpacity` |
97+
| getDateStr | - | Function | A function to override how to format the date into a `String` for display, receives a `Date` instance
9798

9899
### Property `customStyles` available keys
99100

datepicker.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,15 @@ class DatePicker extends Component {
158158
getDateStr(date = this.props.date) {
159159
const {mode, format = FORMATS[mode]} = this.props;
160160

161-
if (date instanceof Date) {
162-
return Moment(date).format(format);
163-
} else {
164-
return Moment(this.getDate(date)).format(format);
161+
const dateInstance = date instanceof Date
162+
? date
163+
: this.getDate(date);
164+
165+
if (typeof this.props.getDateStr === 'function') {
166+
return this.props.getDateStr(dateInstance);
165167
}
168+
169+
return Moment(dateInstance).format(format);
166170
}
167171

168172
datePicked() {
@@ -277,7 +281,8 @@ class DatePicker extends Component {
277281
TimePickerAndroid.open({
278282
hour: timeMoment.hour(),
279283
minute: timeMoment.minutes(),
280-
is24Hour: is24Hour
284+
is24Hour: is24Hour,
285+
mode: androidMode
281286
}).then(this.onTimePicked);
282287
} else if (mode === 'datetime') {
283288
// 选日期和时间
@@ -335,7 +340,8 @@ class DatePicker extends Component {
335340
testID,
336341
cancelBtnTestID,
337342
confirmBtnTestID,
338-
allowFontScaling
343+
allowFontScaling,
344+
locale
339345
} = this.props;
340346

341347
const dateInputStyle = [
@@ -392,8 +398,9 @@ class DatePicker extends Component {
392398
maximumDate={maxDate && this.getDate(maxDate)}
393399
onDateChange={this.onDateChange}
394400
minuteInterval={minuteInterval}
395-
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes}
401+
timeZoneOffsetInMinutes={timeZoneOffsetInMinutes ? timeZoneOffsetInMinutes : null}
396402
style={[Style.datePicker, customStyles.datePicker]}
403+
locale={locale}
397404
/>
398405
</View>
399406
<TouchableComponent
@@ -475,7 +482,9 @@ DatePicker.propTypes = {
475482
onPressMask: PropTypes.func,
476483
placeholder: PropTypes.string,
477484
modalOnResponderTerminationRequest: PropTypes.func,
478-
is24Hour: PropTypes.bool
485+
is24Hour: PropTypes.bool,
486+
getDateStr: PropTypes.func,
487+
locale: PropTypes.string,
479488
};
480489

481490
export default DatePicker;

style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let style = StyleSheet.create({
4545
position: 'absolute',
4646
top: 0,
4747
height: 42,
48-
padding: 20,
48+
paddingHorizontal: 20,
4949
flexDirection: 'row',
5050
alignItems: 'center',
5151
justifyContent: 'center'

0 commit comments

Comments
 (0)