koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

Date-Times can't select a correct date for month less than 31 days #410

Open chufengli opened 1 year ago

chufengli commented 1 year ago

I found if I choose a date in Date Time picker, I can't choose any date if this month has less than 31 days. it will jump to next month.

ie.

select 2/2 15:00:00, the result will be 3/2 15:00:00 select 4/1 15:00:00, the result will be 5/1 15:00:00

any ideas?

mikemak2001 commented 5 months ago

Hi! The cause of the problem in mixins\DateProperty.js in getDateTime because today 31 day > 29

const getDateTime = (parts) => {
  const date = new Date()                               //  Wed Jan 31!!! 2024 15:12:08

  const dateParts = parts[0].split('-')
  date.setFullYear(Number(dateParts[0]))
  date.setMonth(Number(dateParts[1]) - 1) // Try set Feb on  31!!!
  date.setDate(Number(dateParts[2]))
  const timeParts = parts[1].split(':')
  date.setHours(Number(timeParts[0] || '00'))
  date.setMinutes(Number(timeParts[1] || '00'))
  date.setSeconds(0)
  return getDateTimeWithOffset(date)
}

same case

fix work for me

const getDateTime = (parts) => {

    const dateParts = parts[0].split('-');
    const timeParts = parts[1].split(':');
    const date = new Date(
        Number(dateParts[0]),
        Number(dateParts[1]) - 1,
        Number(dateParts[2]),
        Number(timeParts[0] || '00'),
        Number(timeParts[1] || '00'), 0);

    return getDateTimeWithOffset(date)
}