Skip to content

add dateFormatter prop to dateTimePicker #1027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/components/dateTimePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ class DateTimePicker extends BaseComponent {
* The date format for the text display
*/
dateFormat: PropTypes.string,
/**
* A callback function to format date
*/
dateFormatter: PropTypes.func,
/**
* The time format for the text display
*/
timeFormat: PropTypes.string,
/**
* A callback function to format time
*/
timeFormatter: PropTypes.func,
/**
* Allows changing of the locale of the component (iOS only)
*/
Expand Down Expand Up @@ -140,17 +148,22 @@ class DateTimePicker extends BaseComponent {

getStringValue = () => {
const {value} = this.state;
const {mode, dateFormat, timeFormat} = this.getThemeProps();
const {mode, dateFormat, timeFormat, dateFormatter, timeFormatter} = this.getThemeProps();
if (value) {
const dateString =
mode === MODES.DATE
? dateFormat
? moment(value).format(dateFormat)
: value.toLocaleDateString()
: timeFormat
? moment(value).format(timeFormat)
: value.toLocaleTimeString();
return dateString;
switch (mode) {
case MODES.DATE:
return dateFormatter
? dateFormatter(value)
: dateFormat
? moment(value).format(dateFormat)
: value.toLocaleDateString();
case MODES.TIME:
return timeFormatter
? timeFormatter(value)
: timeFormat
? moment(value).format(timeFormat)
: value.toLocaleTimeString();
}
}
};

Expand Down Expand Up @@ -191,12 +204,7 @@ class DateTimePicker extends BaseComponent {
iconStyle={{tintColor: Colors.dark10}}
onPress={this.toggleExpandableOverlay}
/>
<Button
link
iconSource={Assets.icons.check}
useCustomTheme={useCustomTheme}
onPress={this.onDonePressed}
/>
<Button link iconSource={Assets.icons.check} useCustomTheme={useCustomTheme} onPress={this.onDonePressed}/>
</View>
);
}
Expand Down