Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/Calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ export default class Calendar extends Component {
this._minDate = parse(props.minDate);
this._maxDate = parse(props.maxDate);

//validate min/max inputs
if(isNaN(this._min.getTime())) this._min = new Date(1980, 0, 1);
if(isNaN(this._minDate.getTime())) this._minDate = new Date(1980, 0, 1);
if(isNaN(this._max.getTime())) this._max = new Date(2050, 11, 31);
if(isNaN(this._maxDate.getTime())) this._max = new Date(2050, 11, 31);
if(this._min>this._max) {
var temp = this._min;
this._min = this._max;
this._max = temp;
}

const min = this._min.getFullYear();
const minMonth = this._min.getMonth();
const max = this._max.getFullYear();
Expand Down
4 changes: 2 additions & 2 deletions src/Calendar/withDateSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const enhanceDay = withPropsOnChange(['selected'], props => ({
}));

const enhanceYear = withPropsOnChange(['selected'], ({selected}) => ({
selected: parse(selected),
selected: isNaN(parse(selected).getTime()) ? null : parse(selected),
}));

// Enhancer to handle selecting and displaying a single date
Expand All @@ -29,7 +29,7 @@ export const withDateSelection = compose(
DayComponent: enhanceDay(DayComponent),
YearsComponent: enhanceYear(YearsComponent),
})),
withState('scrollDate', 'setScrollDate', props => props.selected || new Date()),
withState('scrollDate', 'setScrollDate', props => sanitizeDate(props.selected,props) || new Date()),
withProps(({onSelect, setScrollDate, ...props}) => {
const selected = sanitizeDate(props.selected, props);

Expand Down
1 change: 1 addition & 0 deletions src/Calendar/withMultipleDates.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function handleYearSelect(date, callback) {
}

function getInitialDate({selected}) {
if(!selected || !selected[0] || isNaN(selected[0].getTime())) return new Date();
return selected.length ? selected[0] : new Date();
}

Expand Down
7 changes: 4 additions & 3 deletions src/Calendar/withRange.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {compose, withProps, withPropsOnChange, withState} from 'recompose';
import classNames from 'classnames';
import {withDefaultProps} from './';
import {withImmutableProps} from '../utils';
import {sanitizeDate, withImmutableProps} from '../utils';
import isBefore from 'date-fns/is_before';
import enhanceHeader from '../Header/withRange';
import format from 'date-fns/format';
Expand Down Expand Up @@ -73,8 +73,8 @@ export const withRange = compose(
},
},
selected: {
start: format(selected.start, 'YYYY-MM-DD'),
end: format(selected.end, 'YYYY-MM-DD'),
start: format((sanitizeDate(selected.start,props) ? selected.start : new Date()), 'YYYY-MM-DD'),
end: format((sanitizeDate(selected.end,props) ? selected.end : new Date()), 'YYYY-MM-DD'),
},
})),
);
Expand Down Expand Up @@ -125,6 +125,7 @@ function handleYearSelect(date, {displayKey, onSelect, selected, setScrollDate})
}

function getInitialDate({selected}) {
if(!selected || !selected.start || isNaN(selected.start.getTime())) return new Date();
return selected.start || new Date();
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function sanitizeDate(date, {
// Selected date should not be disabled or outside the selectable range
if (
!date ||
isNaN(date.getTime()) ||
disabledDates.some(disabledDate => isSameDay(disabledDate, date)) ||
disabledDays && disabledDays.indexOf(getDay(date)) !== -1 ||
minDate && isBefore(date, startOfDay(minDate)) ||
Expand Down