onefinestay / react-daterange-picker

Other
563 stars 208 forks source link

component breaks when moment-timezone default tz is set #130

Open egadstar opened 8 years ago

egadstar commented 8 years ago

This can be easily tested by including moment-timezone and setting the default timezone in the examples.

import momentTz from 'moment-timezone'; ... momentTz.tz.setDefault('America/Chicago'); // freeze date to April 1st timekeeper.freeze(new Date('2015-04-01')); ...

Basically, multiple issues occur:

1) Cannot toggle through months 2) The weekend styles are applied to Sunday and Monday 3) Lots of dates are not selectable within the min and max 4) Calendars displayed are one month behind 5) In certain cases, you are unable to select any dates.

Good example without moment-timezone

screen shot 2016-03-08 at 2 51 58 pm

Broken examples with moment-timezone

screen shot 2016-03-08 at 2 52 13 pm screen shot 2016-03-08 at 2 42 44 pm
josephj commented 8 years ago

+1 have the same issue on switching months

olslash commented 8 years ago

+1, seems to only happen when my physical tz and moment.tz default differ

jontelm commented 7 years ago
calendar(firstOfWeek, firstOfMonth) {
    const start = moment(firstOfMonth.startOf('month')).startOf('week');
    const end = moment(firstOfMonth.endOf('month')).endOf('week');
    const range = moment.range(
      start,
      end
    );
    const array = [];
    let week = [];
    range.by('day', (day) => {
      week.push(day);
      if (week.length === 7) {
        array.push(week);
        week = [];
      }
    });
    return array;
  },

  render() {
    let {firstOfWeek, firstOfMonth} = this.props;

    let monthDates = Immutable.fromJS(this.calendar(firstOfWeek, firstOfMonth));
    let weeks = monthDates.map(this.renderWeek);

I think this works and we can remove the dependency of 'calendar'

maxieduncan commented 6 years ago

+1 also just hit this when changing months