Skip to content

Commit 6a385ca

Browse files
steven-supersoliddrew-gross
authored andcommitted
Fix calendar month/current selection and clicking (#555)
* 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
1 parent 883ee0b commit 6a385ca

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/components/Calendar/Calendar.react.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class Calendar extends React.Component {
5151
<div className={styles.month}>
5252
<a href='javascript:;' role='button' onClick={this.handlePrev.bind(this)} />
5353
<a href='javascript:;' role='button' onClick={this.handleNext.bind(this)} />
54-
<div>{getMonth(this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')]()) + ' ' + this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')]()}</div>
54+
<div>{getMonth(this.state.currentMonth.getMonth()) + ' ' + this.state.currentMonth.getFullYear()}</div>
5555
</div>
5656
);
5757
}
@@ -67,10 +67,10 @@ export default class Calendar extends React.Component {
6767
renderDays() {
6868
let isValueMonth = (
6969
this.props.value &&
70-
this.props.value[getDateMethod(this.props.local, 'getFullYear')]() === this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')]() &&
71-
this.props.value[getDateMethod(this.props.local, 'getMonth')]() === this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')]()
70+
this.props.value[getDateMethod(this.props.local, 'getFullYear')]() === this.state.currentMonth.getFullYear() &&
71+
this.props.value[getDateMethod(this.props.local, 'getMonth')]() === this.state.currentMonth.getMonth()
7272
);
73-
let offset = this.state.currentMonth[getDateMethod(this.props.local, 'getDay')]();
73+
let offset = this.state.currentMonth.getDay();
7474
let days = daysInMonth(this.state.currentMonth);
7575
let labels = [];
7676
for (let i = 0; i < offset; i++) {
@@ -81,7 +81,9 @@ export default class Calendar extends React.Component {
8181
let className = isSelected ? styles.selected : '';
8282
let onChange = this.props.onChange.bind(
8383
null,
84-
new Date(this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')](), this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')](), i)
84+
this.props.local ?
85+
new Date(this.state.currentMonth.getFullYear(), this.state.currentMonth.getMonth(), i) :
86+
new Date(Date.UTC(this.state.currentMonth.getFullYear(), this.state.currentMonth.getMonth(), i))
8587
);
8688
labels.push(
8789
<a href='javascript:;' role='button' key={'day' + i} className={className} onClick={onChange}>{i}</a>

0 commit comments

Comments
 (0)