From 21c24d0211ddae8fdc17c121449a60b79e983cd3 Mon Sep 17 00:00:00 2001 From: "dmitrijs.jonins@the-contactgroup.com" Date: Thu, 14 Apr 2016 12:21:07 +0100 Subject: [PATCH 1/2] allow empty or invalid initial date --- src/DateTimeField.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/DateTimeField.js b/src/DateTimeField.js index 2e2d342b..5d4e2ea9 100644 --- a/src/DateTimeField.js +++ b/src/DateTimeField.js @@ -61,16 +61,16 @@ export default class DateTimeField extends Component { left: -9999, zIndex: "9999 !important" }, - viewDate: moment(this.props.dateTime, this.props.format, true).startOf("month"), + viewDate: moment(this.props.dateTime, this.props.format, true).isValid() ? moment(this.props.dateTime, this.props.format, true).startOf("month") : moment().startOf("month"), selectedDate: moment(this.props.dateTime, this.props.format, true), - inputValue: typeof this.props.defaultText !== "undefined" ? this.props.defaultText : moment(this.props.dateTime, this.props.format, true).format(this.resolvePropsInputFormat()) + inputValue: typeof this.props.defaultText !== "undefined" ? this.props.defaultText : (moment(this.props.dateTime, this.props.format, true).isValid() ? moment(this.props.dateTime, this.props.format, true).format(this.resolvePropsInputFormat()) : '') } componentWillReceiveProps = (nextProps) => { let state = {}; if (nextProps.inputFormat !== this.props.inputFormat) { state.inputFormat = nextProps.inputFormat; - state.inputValue = moment(nextProps.dateTime, nextProps.format, true).format(nextProps.inputFormat); + state.inputValue = moment(nextProps.dateTime, nextProps.format, true).isValid() ? moment(nextProps.dateTime, nextProps.format, true).format(nextProps.inputFormat) : ''; } if (nextProps.dateTime !== this.props.dateTime && moment(nextProps.dateTime, nextProps.format, true).isValid()) { @@ -112,7 +112,7 @@ export default class DateTimeField extends Component { else if (target.className.indexOf("old") >= 0) month = this.state.viewDate.month() - 1; else month = this.state.viewDate.month(); return this.setState({ - selectedDate: this.state.viewDate.clone().month(month).date(parseInt(e.target.innerHTML)).hour(this.state.selectedDate.hours()).minute(this.state.selectedDate.minutes()) + selectedDate: this.state.selectedDate.isValid() ? this.state.viewDate.clone().month(month).date(parseInt(e.target.innerHTML)).hour(this.state.selectedDate.hours()).minute(this.state.selectedDate.minutes()) : this.state.viewDate.clone().month(month).date(parseInt(e.target.innerHTML)) }, function() { this.closePicker(); this.props.onChange(this.state.selectedDate.format(this.props.format)); @@ -240,7 +240,7 @@ export default class DateTimeField extends Component { } togglePeriod = () => { - if (this.state.selectedDate.hour() > 12) { + if (this.state.selectedDate.hour() >= 12) { return this.onChange(this.state.selectedDate.clone().subtract(12, "hours").format(this.state.inputFormat)); } else { return this.onChange(this.state.selectedDate.clone().add(12, "hours").format(this.state.inputFormat)); @@ -248,6 +248,16 @@ export default class DateTimeField extends Component { } togglePicker = () => { + if(!this.state.selectedDate.isValid()) { + this.setState({ + selectedDate: moment().startOf('day') + }, function() { + this.props.onChange(this.state.selectedDate.format(this.props.format)); + return this.setState({ + inputValue: this.state.selectedDate.format(this.state.inputFormat) + }); + }); + } return this.setState({ showDatePicker: !this.state.showDatePicker, showTimePicker: !this.state.showTimePicker From 8dee96c5a2a53a3bebc697a8cde106527e88883c Mon Sep 17 00:00:00 2001 From: Matthew Harris Date: Wed, 20 Apr 2016 14:49:37 +0100 Subject: [PATCH 2/2] Changed order of headers to fit days --- src/DateTimePickerDays.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DateTimePickerDays.js b/src/DateTimePickerDays.js index 11fae8ed..feb48b74 100644 --- a/src/DateTimePickerDays.js +++ b/src/DateTimePickerDays.js @@ -82,8 +82,6 @@ export default class DateTimePickerDays extends Component { - Su - Mo Tu @@ -95,6 +93,8 @@ export default class DateTimePickerDays extends Component { Fr Sa + + Su