Skip to content

Commit

Permalink
feat: add getDateStr prop to customize display outside moment format
Browse files Browse the repository at this point in the history
  • Loading branch information
blackxored committed Jan 5, 2018
1 parent 58ed2b1 commit 905dfbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ You can check [index.js](https://github.com/xgfe/react-native-datepicker/blob/ma
| onPressMask | - | `function` | This is called when clicking the ios modal mask |
| 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. |
| TouchableComponent | `TouchableHighlight` | `Component` | Replace the `TouchableHighlight` with a custom `Component`. For example : `TouchableOpacity` |
| getDateStr | - | Function | A function to override how to format the date into a `String` for display, receives a `Date` instance

### Property `customStyles` available keys

Expand Down
15 changes: 10 additions & 5 deletions datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@ class DatePicker extends Component {
getDateStr(date = this.props.date) {
const {mode, format = FORMATS[mode]} = this.props;

if (date instanceof Date) {
return Moment(date).format(format);
} else {
return Moment(this.getDate(date)).format(format);
const dateInstance = date instanceof Date
? date
: this.getDate(date);

if (typeof this.props.getDateStr === 'function') {
return this.props.getDateStr(dateInstance);
}

return Moment(dateInstance).format(format);
}

datePicked() {
Expand Down Expand Up @@ -471,7 +475,8 @@ DatePicker.propTypes = {
onPressMask: PropTypes.func,
placeholder: PropTypes.string,
modalOnResponderTerminationRequest: PropTypes.func,
is24Hour: PropTypes.bool
is24Hour: PropTypes.bool,
getDateStr: PropTypes.func
};

export default DatePicker;

0 comments on commit 905dfbd

Please sign in to comment.