From df932d091c2c32eda2a0a30304b4e1f30aecd202 Mon Sep 17 00:00:00 2001 From: steven-supersolid Date: Mon, 17 Oct 2016 15:04:25 +0100 Subject: [PATCH 1/2] Ensure currentMonth is created in UTC and remove optional timezone conversion for currentMonth --- src/components/Calendar/Calendar.react.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Calendar/Calendar.react.js b/src/components/Calendar/Calendar.react.js index d47fd51a6e..a66d80e0db 100644 --- a/src/components/Calendar/Calendar.react.js +++ b/src/components/Calendar/Calendar.react.js @@ -22,14 +22,14 @@ export default class Calendar extends React.Component { super(); let now = props.value || new Date(); this.state = { - currentMonth: new Date(now[getDateMethod(props.local, 'getFullYear')](), now[getDateMethod(props.local, 'getMonth')](), 1) + currentMonth: new Date(Date.UTC(now[getDateMethod(props.local, 'getFullYear')](), now[getDateMethod(props.local, 'getMonth')](), 1)) }; } componentWillReceiveProps(props) { if (props.value) { this.setState({ - currentMonth: new Date(props.value[getDateMethod(props.local, 'getFullYear')](), props.value[getDateMethod(props.local, 'getMonth')](), 1) + currentMonth: new Date(Date.UTC(props.value[getDateMethod(props.local, 'getFullYear')](), props.value[getDateMethod(props.local, 'getMonth')](), 1)) }); } } @@ -51,7 +51,7 @@ export default class Calendar extends React.Component {
-
{getMonth(this.state.currentMonth[getDateMethod(this.props.local, 'getMonth')]()) + ' ' + this.state.currentMonth[getDateMethod(this.props.local, 'getFullYear')]()}
+
{getMonth(this.state.currentMonth.getMonth()) + ' ' + this.state.currentMonth.getFullYear()}
); } @@ -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++) { @@ -81,7 +81,7 @@ 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) + new Date(Date.UTC(this.state.currentMonth.getFullYear(), this.state.currentMonth.getMonth(), i)) ); labels.push( {i} From b37264633a23ee66a5f9b94b74730b9ecba49e9d Mon Sep 17 00:00:00 2001 From: steven-supersolid Date: Tue, 18 Oct 2016 05:15:14 +1400 Subject: [PATCH 2/2] currentMonth is now local time. Convert onChange date fired to timezone to match props.local --- src/components/Calendar/Calendar.react.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/Calendar/Calendar.react.js b/src/components/Calendar/Calendar.react.js index a66d80e0db..64076468c6 100644 --- a/src/components/Calendar/Calendar.react.js +++ b/src/components/Calendar/Calendar.react.js @@ -22,14 +22,14 @@ export default class Calendar extends React.Component { super(); let now = props.value || new Date(); this.state = { - currentMonth: new Date(Date.UTC(now[getDateMethod(props.local, 'getFullYear')](), now[getDateMethod(props.local, 'getMonth')](), 1)) + currentMonth: new Date(now[getDateMethod(props.local, 'getFullYear')](), now[getDateMethod(props.local, 'getMonth')](), 1) }; } componentWillReceiveProps(props) { if (props.value) { this.setState({ - currentMonth: new Date(Date.UTC(props.value[getDateMethod(props.local, 'getFullYear')](), props.value[getDateMethod(props.local, 'getMonth')](), 1)) + currentMonth: new Date(props.value[getDateMethod(props.local, 'getFullYear')](), props.value[getDateMethod(props.local, 'getMonth')](), 1) }); } } @@ -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(Date.UTC(this.state.currentMonth.getFullYear(), this.state.currentMonth.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( {i}