Skip to content

issue with leap year while typing #659

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

Closed
2 tasks done
kumarrsk opened this issue Apr 10, 2024 · 4 comments · May be fixed by #695
Closed
2 tasks done

issue with leap year while typing #659

kumarrsk opened this issue Apr 10, 2024 · 4 comments · May be fixed by #695
Labels
bug Something isn't working stale

Comments

@kumarrsk
Copy link

Before you start - checklist

  • I followed instructions in documentation written for my React-Date-Picker version
  • I have checked if this bug is not already reported

Description

Hi,
I have set the date format on my date picker as MM/dd/yyyy.
However, when the user writes a date in the input, for example 02/29/200 , the date picker value becomes 03/01/200 , so it looks like the date format is still the original for the user input.
Has anyone had this issue before and knows a solution?

Steps to reproduce

change the format to MM/dd/yyyy
type 02/29/200
it will change to 03/01/200

Expected behavior

till needs to wait to add complete year

Actual behavior

changing the date to next day

Additional information

No response

Environment

  • Browser (if applicable):
  • React-Date-Picker version:
  • React version:
@kumarrsk kumarrsk added the bug Something isn't working label Apr 10, 2024
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Jul 15, 2024
Copy link
Contributor

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
@dagjomar
Copy link

This is still an issue in version 10.6.0 which is causing a problem for us.

dagjomar pushed a commit to dagjomar/react-date-picker that referenced this issue Apr 25, 2025
Fixes: wojtekmaj#659

There is an issue when trying to input a date such as "29 / 02 / 2024"
(February 29th 2024) which is a leap year and should be valid.

The validation runs into a state where the input fields are first rendered
with the inputs
day: 29
month: 2
year: 202

which is not a leap year, and thus the day 29 is not valid for this state.

The problem occurs when running the onChangeExternal,
which tries to read the validity state of the dayInput react Ref.
However, that ref has last been rendered with a min/max number value
calculated from the previous month and year (month 2 and year 202).
Therefore the day input field still believes that the day 29 is not valid,
even though we have just entered 2024 into the year field.

This workaround is to just use a new instance of a DOM input field that
emulates what the real input field should do,
and check this validity value instead, which will be correct using the current updated values.
The real input field values will become valid next render cycle.
Ironic to make another "shadow DOM" inside react, but at least it works.

Added a bunch of unit tests for this case, and improved the
test coverage of utility methods as well
@dagjomar
Copy link

Pull request with fix sent: #695

@kumarrsk you might want to comment on that and improve chances to get it merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants