Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix selected date in calendar for different timezones #45

Merged
merged 1 commit into from Jan 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/travix-ui-kit/components/calendar/calendar.js
Expand Up @@ -155,10 +155,15 @@ export default class Calendar extends Component {
* passing the selectedDates array to it.
*
* @method onSelectDay
* @param {Date} dateSelected Date selected by the user.
* @param {String} dateStr Date selected by the user.
*/
onSelectDay(dateSelected) {
onSelectDay(dateStr) {
const { onSelectDay, selectionType, minDate, multiplemode } = this.props;
const currentDate = new Date(dateStr);
const yearSelected = currentDate.getUTCFullYear();
const monthSelected = currentDate.getUTCMonth();
const daySelected = currentDate.getUTCDate();
const dateSelected = new Date(yearSelected, monthSelected, daySelected);

this.setState((prevState) => {
let { minLimit, renderDate, selectedDates } = prevState;
Expand Down Expand Up @@ -246,7 +251,7 @@ export default class Calendar extends Component {
onMouseDown={this.handleItemMouseDown}
onNavNextMonth={() => this.moveToMonth(CALENDAR_MOVE_TO_NEXT)}
onNavPreviousMonth={() => this.moveToMonth(CALENDAR_MOVE_TO_PREVIOUS)}
onSelectDay={e => this.onSelectDay(new Date(e.currentTarget.getAttribute('data-date')))}
onSelectDay={e => this.onSelectDay(e.currentTarget.getAttribute('data-date'))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to not pass a date object to onSelectDay anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No any specific reason, for me it just looks better and simpler.

renderDate={renderDate}
selectedDates={selectedDates}
selectionType={selectionType}
Expand Down