Skip to content

Commit

Permalink
fixes for disabled dates through handler. Still pending issue with na…
Browse files Browse the repository at this point in the history
…tive dates and trySetState
  • Loading branch information
harel committed Apr 17, 2017
1 parent 92132ce commit 49e5c3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
13 changes: 7 additions & 6 deletions src/modules/Datetime/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,22 @@ export default class Calendar extends Component {
setDay = (e, day) => {
e.stopPropagation()
const {value, mode} = this.state
const { onDateSelect, time, range } = this.props
const date = new this.Date(value)
date.day(day)
debugger
const { onDateSelect, time } = this.props
const selectedDate = date.getDate()
const nextMode = time ? 'hour' : mode
const rangeState = {}
if (this.props.range) {
if (range) {
rangeState.selectionStart = date
}
this.trySetState({
value: date.getDate(),
value: selectedDate,
mode: nextMode,
...rangeState,
})
if (!time && onDateSelect) {
onDateSelect(e, date.getDate())
onDateSelect(e, selectedDate)
}
}

Expand Down Expand Up @@ -279,11 +279,12 @@ export default class Calendar extends Component {
render() {
const { date } = this.props
const { mode, value } = this.state
const calendarDay = this.getDate()
return (
<div style={style}>
{date && (
<CalendarMenu
value={this.getDate()}
value={calendarDay}
monthName={this.getMonthName()}
year={this.getYear()}
mode={mode}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/Datetime/Month.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export default class Month extends Component {
getDays() {
const { date, onClick, disabledDates } = this.props
const { selectionStart, selectionEnd } = this.state
console.log('disabltd', disabledDates)
const _date = new this.Date(date)

const firstDay = _date.getFirstOfMonth()
const firstWeekDay = _date.getWeekDay(firstDay)
const daysInMonth = _date.daysInMonth()
Expand Down Expand Up @@ -144,7 +144,7 @@ export default class Month extends Component {
dayParams.selected = this.isCellSelected(dayCellDate, selectionStart, selectionEnd)

if (hasDisabledDates && !dayParams.disabled &&
disabledDateSig.indexOf(this.getDateString(dayParams.date)) > -1) {
disabledDateSig.indexOf(_date.getDateString(dayCellDate.getDate())) > -1) {
dayParams.disabled = true
}
return dayParams
Expand Down
7 changes: 4 additions & 3 deletions src/modules/Datetime/handlers/moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export function getMomentDateHandler(settings={}) {
class DateHandler {
static settings = settings
constructor(date) {
if (!date) {
date = moment.tz()
}
if (date.tz && date.tz()) {
this.timeZone = date.tz()
} else {
this.timeZone = settings.timeZone || null
}
if (date) {
this.set(date)
}
this.set(date)
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/modules/Datetime/handlers/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export function getNativeDateHandler(settings={}) {
class DateHandler {
static settings = settings
constructor(date) {
if (date) {
this.set(date)
}
this.set(date)
}

/**
Expand All @@ -28,7 +26,11 @@ export function getNativeDateHandler(settings={}) {
* re/set a new date on this instance
*/
set(date) {
this.date = new Date(date)
if (typeof(date) == 'string' && date.trim().length == 0) {
this.date = new Date()
} else {
this.date = new Date(date)
}
return this
}

Expand Down Expand Up @@ -166,7 +168,7 @@ export function getNativeDateHandler(settings={}) {
}

/**
* Get or set the date of the date
* Get or set the calendar date of the date
*/
day(value) {
if (value) {
Expand Down

0 comments on commit 49e5c3b

Please sign in to comment.