danruggi / datepicker

Ultralight datepicker vanilla JS CSS with no dependencies
MIT License
7 stars 0 forks source link

On 31st of Month, issue when choosing a month with less than 31 days #1

Open lamselli opened 1 year ago

lamselli commented 1 year ago

Today is 05/31. If I try to pick a date in june, the date filled will be in July.

lamselli commented 1 year ago

I think the issue comes from that bit of code :

let centerDate = new Date();

    if (idA[1] == "anyDate") {
        input.value = "";
    } else {
        centerDate.setUTCFullYear(idA[1]);
        centerDate.setUTCMonth(idA[2]-1);
        centerDate.setUTCDate(idA[3]);
        // input.value = centerDate;
        input.value = centerDate.getUTCFullYear()+"-"+String(parseInt(centerDate.getUTCMonth())+1).padStart(2,"0")+"-"+String(parseInt(centerDate.getUTCDate())).padStart(2,'0');
    }

When you'll set the month, it wont be correct as the date is 31. You should set date before setting the month or create a more specific center date, I think.

Thanks for this great library !

danruggi commented 1 week ago

I releasd a new version, completely revisited. On the last day of Oct I'll check if it works, I think the problem was with UTC, I set this new version to use just local dates