primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
10.58k stars 1.23k forks source link

DatePicker: does not handle correctly some dates on manual input #6361

Open Florian-Mt opened 2 months ago

Florian-Mt commented 2 months ago

Describe the bug

It is not possible to manually input a date with year less than 1000, except by adding a leading 0. However, this zero gets immediately removed, so it is necessary to add it again and again every time to input another year < 1000.

Adding dateFormat='dd/mm/yy' does not fix it either. This pattern does not actually print the date on four digits as stated in the docs. The reason why is here: https://github.com/primefaces/primevue/blob/master/packages/primevue/src/datepicker/DatePicker.vue#L1375). output += lookAhead('y') ? date.getFullYear() : ... should probably be replaced by output += lookAhead('y') ? `${date.getFullYear()}`.padStart(4, '0') : ....

Same problem for years Y less than 100, but the year also jumps automatically to 1900 + Y or 2000 + Y, which is actually undesired in some situations. It's the same for UI input, i.e. non-manual.

Same problem with date having year more than 9999. No way to manually input such a date, it gets ignored. However, dates in JS can go up to year 275 760.

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-8hhozk?file=src%2FApp.vue

PrimeVue version

3.53.0, 4.0.5

Vue version

3.x

Language

ALL

Build / Runtime

Vite

Browser(s)

ALL

Steps to reproduce the behavior

Using the plain date picker (for example in the docs page)

  1. Manual input '01/01/1000' → OK
  2. Manual input '01/01/999' → Rejected
  3. Manual input '01/01/0999' → OK but formatted as '01/01/999', whatever the format
  4. Manual input '01/01/0099' → OK but jumps to 1999!
  5. Manual input '01/01/10000' → Rejected

Expected behavior

  1. Manual input '01/01/1000' → OK
  2. Manual input '01/01/999' → unsure
  3. Manual input '01/01/0999' → OK, formatted as '01/01/0999' (at least for 'yy' format)
  4. Manual input '01/01/0099' → OK, formatted as '01/01/0099'
  5. Manual input '01/01/10000' → OK
timothymarois commented 4 days ago

I actually find that manual-input is suppose to be set to true, but it doesn't work at all, always clears out the value when using only-time