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

minDate and maxDate not adhering to UTC offset when select is missing #747

Closed
eastwood opened this issue Feb 23, 2017 · 5 comments
Closed

Comments

@eastwood
Copy link

eastwood commented Feb 23, 2017

After some preliminary investigation, it seems that when there is no select prop present, the minDate and maxDate values to not adhere to the utcOffset.

Demo project: https://github.com/eastwood/react-datepicker-fix.
I'd expect to have the same disabled days for the following:

  1. Australia/Sydney time is 24th February 00:00 UTC+10
  2. America/Los Angeles time is 23rd February 05:00 UTC-8
  3. If I'm in UTC-8 (Los Angeles) time and the following settings are set
  4. Set minDate={moment()}
  5. Set selected={null}
  6. Set utcOffset={10}

I'd expect to only be able to choose dates from the 24th February onwards.
Unfortunately, the 23rd February is enabled.
However, if I set selected to anything, i.e selected={moment().subtract(2, 'days')}, then the correct dates will be disabled.

To test this:

  1. Clone repo
  2. Change system timezone accordingly
  3. Start application with npm run start
  4. Note that the I have the utcOffset=10. So feel free to play with it to cross a day boundary.

I'll do some more investigation into this and happy to submit PR afterwards.

@martijnrusschen
Copy link
Member

+1 on more investigation and a fix :) Happy to help reviewing any solutions for you.

@dvdgarcia
Copy link

dvdgarcia commented May 16, 2017

+1 The issue as well happens without setting the offset.

For example if in excludeDates a I exclude tomorrow and next tomorrow when I open the datepicker I see today and tomorrow disabled, then I select next tomorrow, the date picker is closed I open again and I see what I was expecting originally(tomorrow and next tomorrow disabled, and yes as date selected I have nextTomorrow xD )

On my case I have the version 0.39.0

<DatePicker dateFormat="DD/MM/YY"
 minDate={moment()} 
className="form-control" 
selected={this.props.value ? moment.unix(this.props.value) : null} 
placeholderText={this.props.placeholder} 
onChange={::this.handleChange}
excludeDates={this.props.excludeDates?this.props.excludeDates:[]}/>

@aij
Copy link
Contributor

aij commented May 16, 2017

@dvdgarcia What time zone are you using for excludeDates?

Things get a little screwy when mixing moments in different UTC offsets. (Which is especially easy to do accidentally when you are in a time zone with daylight savings time...)

@dvdgarcia
Copy link

dvdgarcia commented May 16, 2017

I am in Spain so Madrid+1.

I have to say that I achieved a way for working, if selected value is not null works fine. So the bug is this one:
with this implementation with excludedDates in the same UTC offset:

<DatePicker dateFormat="DD/MM/YY"
 minDate={moment()} 
className="form-control" 
selected={this.props.value ? moment.unix(this.props.value) : null} 
placeholderText={this.props.placeholder} 
onChange={::this.handleChange}
excludeDates={this.props.excludeDates?this.props.excludeDates:[]}/>

I open the date picker and the dates excluded are wrong, I select one, the datepicker is closed, then I open it again and I see the disabled dates as I wanted originally.

So I tried to do this implementation:


<DatePicker dateFormat="DD/MM/YY"
 minDate={moment()} 
className="form-control" 
selected={this.props.value ? moment.unix(this.props.value) : moment()}  <---THIS IS THE CHANGE 
placeholderText={this.props.placeholder} 
onChange={::this.handleChange}
excludeDates={this.props.excludeDates?this.props.excludeDates:[]}/>

I initialize the selected value with moment() and it works perfect. I see the disabled dates that I send as paramter
In my case I don't wanna initialize the date picker but I will do if I have not other option..

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 30, 2019
@stale stale bot closed this as completed Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants