Skip to content

Commit

Permalink
produce raw date when no format is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Apr 24, 2018
1 parent f61081a commit 5a6e4e0
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/components/EditorWidgets/Date/DateControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default class DateControl extends React.Component {
includeTime: PropTypes.bool,
};

formatOutput = this.props.field.get('format');
formatDisplay = this.formatOutput || (this.props.includeTime ? DEFAULT_DATETIME_FORMAT : DEFAULT_DATE_FORMAT);
format = this.props.field.get('format');

componentDidMount() {
const { value } = this.props;
Expand Down Expand Up @@ -53,11 +52,12 @@ export default class DateControl extends React.Component {
* Produce a formatted string only if a format is set in the config.
* Otherwise produce a date object.
*/
if (this.formatOutput) {
const formattedValue = moment(datetime).format(this.formatOutput);
if (this.format) {
const formattedValue = moment(datetime).format(this.format);
onChange(formattedValue);
} else {
onChange(datetime);
const value = moment.isMoment(datetime) ? datetime.toDate() : datetime;
onChange(value);
}
};

Expand All @@ -79,11 +79,10 @@ export default class DateControl extends React.Component {

render() {
const { includeTime, value, classNameWrapper, setActiveStyle, setInactiveStyle } = this.props;
const format = this.formatDisplay;
return (
<DateTime
timeFormat={!!includeTime}
value={moment(value, format)}
value={moment(value, this.format)}
onChange={this.handleChange}
onFocus={setActiveStyle}
onBlur={this.onBlur}
Expand Down

0 comments on commit 5a6e4e0

Please sign in to comment.