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

Why does isOutsideRange get called multiple times for each date, and at different times (midnight vs noon)? #2140

Closed
opqpop opened this issue Aug 3, 2021 · 9 comments · Fixed by #2146
Labels
bug Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D

Comments

@opqpop
Copy link

opqpop commented Aug 3, 2021

react-dates version
react-dates@21.8.0

Describe the bug
isOutsideRange prop callback is passing each calendar day multiple times for some reason

specifically, each date can be called at local time midnight or local time noon, which makes it hard for me to know which one I'm supposed to compare for to return a correct value to isOutSideRange

expected behavior: returns consistent time, either always midnight local time or always noon local time

Source code (including props configuration)
Load and see strange output

<DayPickerRangeController
  isOutsideRange={(date) => console.log('huh', date.format())}
/>

image
image

zoom_0.mp4

Desktop (please complete the following information):

  • OS: mac
  • Browser chrome
  • Version 92.0.4515.107 (Official Build) (x86_64)
@ljharb
Copy link
Member

ljharb commented Aug 3, 2021

I'd expect always noon, since midnight doesn't always exist. This seems like a bug.

@ljharb ljharb added bug Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D labels Aug 3, 2021
@glintik
Copy link

glintik commented Sep 19, 2021

Hi @ljharb,

Proposed a fix for this issue, please take a look.
I introduced simple cache to mitigate multiple isOutsideRange and isDayBlocked, it works as expected and tests passed, but would like to see your thoughts about this implementation.

@ljharb
Copy link
Member

ljharb commented Sep 19, 2021

A cache isn’t a good idea, because the callback may need to be called multiple times.

the fix is to not use midnight.

@opqpop
Copy link
Author

opqpop commented Sep 19, 2021

Wow, thanks for both of your help! Exciting to see the potential fix!

@opqpop
Copy link
Author

opqpop commented Apr 7, 2022

Hi, wanted to ask if this ever got fixed? I'm still struggling to figure out how to deal with this, as I'm currently assuming noon time, but it'll still give me midnight time sometimes causing my users to see strange bugs

@opqpop
Copy link
Author

opqpop commented Apr 7, 2022

Ah nvm, sorry for the thrash, I see that #2146 was merged in! Thank you so much for the fix! Will test this out more and see what might be going on

@ljharb
Copy link
Member

ljharb commented Apr 7, 2022

@opqpop it's been merged, but not yet released.

@opqpop
Copy link
Author

opqpop commented Apr 7, 2022

Ah okay thanks, any ETA on when that might be?

Meanwhile, I dug into it and threw in something like this in my callsite, which seems to have helped with some of the bugs

const hoursToAdd = reactDateDay.format('H') == '0' ? 12 : 0
const standardizedDay = reactDateDay.clone().add(hoursToAdd, 'hours')

@nathanredblur
Copy link

I have similar issue, but with timezones
I notice the same date is called multiple times using different timezones.
any idea what could it be?

CleanShot 2023-03-30 at 12 09 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Oh no, something's broken :-( pull request wanted This is a great way to contribute! Help us out :-D
Projects
None yet
4 participants