question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

date-fns DatePicker format bug when typing in the date input

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Type 01/01/2021 in the date input
  2. 01/01/0002021 is entered instead

See Image from Gyazo

What is expected?

01/01/2021 should be entered in the date input

What is actually happening?

01/01/0002021 is entered is the date input

Environment Info
antd 4.15.1
React 17.0.1
System macOS Big Sur 11.2.3
Browser Chrome 89.0.4389.114

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
mk-nickyangcommented, Apr 16, 2021

Actually, I just found a simple workaround that stops leading zeroes being added when typing year.

Instead of using the yyyy pattern,

<DatePicker format="dd/MM/yyyy" />

just using y will do the trick

<DatePicker format="dd/MM/y" />
6reactions
mk-nickyangcommented, Apr 16, 2021

@appleshell Thanks for pointing out the reason mate.

But replacing date-fns with moment or dayjs doesn’t really solve this problem (it’s just a workaround), and I believe most people who switched from moment to date-fns would prefer not to go back

Read more comments on GitHub >

github_iconTop Results From Across the Web

DatePicker has weird behavior with manual typing using date ...
DatePicker has weird behavior with manual typing using date-fns #5221 ... The cursor is moving around like going at the end of the...
Read more >
Material UI DatePicker Showing Wrong Date - Stack Overflow
I've faced the same problem. After all, I added a parseISO method on my date, you need to specify the timezone of the...
Read more >
Datepicker - Angular Material
The datepicker allows users to enter a date either through text input, or by choosing a date from the calendar. It is made...
Read more >
How to use the date-fns.isValid function in date-fns - Snyk
To help you get started, we've selected a few date-fns.isValid examples, based on popular ways it is used in public projects.
Read more >
DatePicker Lightning Web Component ReadMe
error. string. Adds text for an error message. name. string. Adds a name for the date picker. mask. To define how a user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found