Skip to content

Commit

Permalink
Fix calendar month/current selection and clicking (#555)
Browse files Browse the repository at this point in the history
* Ensure currentMonth is created in UTC and remove optional timezone conversion for currentMonth

* currentMonth is now local time. Convert onChange date fired to timezone to match props.local
  • Loading branch information
steven-supersolid authored and drew-gross committed Oct 17, 2016
1 parent 883ee0b commit 6a385ca
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/Calendar/Calendar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class Calendar extends React.Component {
<div className={styles.month}>
<a href='javascript:;' role='button' onClick={this.handlePrev.bind(this)} />
<a href='javascript:;' role='button' onClick={this.handleNext.bind(this)} />
<div>{getMonth(this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')]()) + ' ' + this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')]()}</div>
<div>{getMonth(this.state.currentMonth.getMonth()) + ' ' + this.state.currentMonth.getFullYear()}</div>
</div>
);
}
Expand All @@ -67,10 +67,10 @@ export default class Calendar extends React.Component {
renderDays() {
let isValueMonth = (
this.props.value &&
this.props.value[getDateMethod(this.props.local, 'getFullYear')]() === this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')]() &&
this.props.value[getDateMethod(this.props.local, 'getMonth')]() === this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')]()
this.props.value[getDateMethod(this.props.local, 'getFullYear')]() === this.state.currentMonth.getFullYear() &&
this.props.value[getDateMethod(this.props.local, 'getMonth')]() === this.state.currentMonth.getMonth()
);
let offset = this.state.currentMonth[getDateMethod(this.props.local, 'getDay')]();
let offset = this.state.currentMonth.getDay();
let days = daysInMonth(this.state.currentMonth);
let labels = [];
for (let i = 0; i < offset; i++) {
Expand All @@ -81,7 +81,9 @@ export default class Calendar extends React.Component {
let className = isSelected ? styles.selected : '';
let onChange = this.props.onChange.bind(
null,
new Date(this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')](), this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')](), i)
this.props.local ?
new Date(this.state.currentMonth.getFullYear(), this.state.currentMonth.getMonth(), i) :
new Date(Date.UTC(this.state.currentMonth.getFullYear(), this.state.currentMonth.getMonth(), i))
);
labels.push(
<a href='javascript:;' role='button' key={'day' + i} className={className} onClick={onChange}>{i}</a>
Expand Down

0 comments on commit 6a385ca

Please sign in to comment.