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 off by one date selection issue #7394

Merged
merged 3 commits into from
Mar 24, 2022
Merged

Fix off by one date selection issue #7394

merged 3 commits into from
Mar 24, 2022

Conversation

gwyneplaine
Copy link
Contributor

Resolves #6115

The root of the problem as highlighted in #6115 is inconsistency in how browsers handle new Date(value) where value is some string representation of a Date.

This PR opts for explicitly passing in year month and day to Date for more deterministic behaviour.

@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2022

🦋 Changeset detected

Latest commit: e2fdd38

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 24, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/4aBWLKt64Ld3Pdt8f1ZUv5cNGL5N
✅ Preview: https://keystone-next-docs-git-fix-6115-keystonejs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 24, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@vercel vercel bot temporarily deployed to Preview March 24, 2022 04:03 Inactive
@vercel vercel bot temporarily deployed to Preview March 24, 2022 04:08 Inactive
@vercel vercel bot temporarily deployed to Preview March 24, 2022 04:13 Inactive
@@ -31,6 +31,11 @@ export function useEventCallback<Func extends (...args: any) => any>(callback: F
return cb as any;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

couldn't think of a better name for this fn. suggestions welcome

@gwyneplaine gwyneplaine requested a review from a team March 24, 2022 04:14
@gwyneplaine gwyneplaine enabled auto-merge (squash) March 24, 2022 04:19
@gwyneplaine gwyneplaine merged commit 5d96ee6 into main Mar 24, 2022
@gwyneplaine gwyneplaine deleted the fix/#6115 branch March 24, 2022 04:25
Comment on lines +35 to +36
const [year, month, day] = value.split('-').map(el => parseInt(el, 10));
return new Date(year, month - 1, day);
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, I think you could have

Suggested change
const [year, month, day] = value.split('-').map(el => parseInt(el, 10));
return new Date(year, month - 1, day);
return new Date(value.replace(/-/g, '/'))

Copy link
Member

@dcousens dcousens Mar 24, 2022

Choose a reason for hiding this comment

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

Actually, we should use import { parse } from 'date-fns'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date Picker always changes to the previous day
3 participants