Twipped / Kalendae

A javascript date picker that just works.
MIT License
1.99k stars 285 forks source link

Bug: Range Selector crossing years when reopening #224

Closed stell closed 6 years ago

stell commented 6 years ago

When in range mode and the format is set to something like 'DD.MMM', there is a bug when reopeing the calendar.

Select a range like "28.Dez. - 02.Jan.". So the Selection goes from one year to the next one. Close the picker and open it again. Now a wrong range is selected from "02.Jan. - 28.Dez.".

My config:

cal = new Kalendae.Input("picker", {
    direction: 'today-future',
    months:2,
    closeOnSelection: true,
    format: 'DD.MMM',
    weekStart: 1,
    useYearNav: false,
    mode:'range',
Twipped commented 6 years ago

I'm not sure I can fix this. The issue here is that without a year as part of the parsing, the dates will always be parsed as the current year (2018). So when you select a date that spans the new year, it correctly outputs it, but then when it re-parses those dates on re-opening both dates get treated as 2018, Kalendae sees a start date that is after the end date, knows it can't draw that and it assumes it's a mistake, so it flips the dates to make the range valid. There's no way to tell it that the first date isn't 2018 without parsing an actual year.

stell commented 6 years ago

Well i know that and that's the bug :) Kalendae should access the selected dates from set variable state(s) and not re-parse them from the input field.

Twipped commented 6 years ago

Well, that's not the way it was built. Kalendae is over six years old, it was created for use on plain old forms. Back then the DOM was the authoritative state, and since something else could have altered it outside of my code, I had to reparse on focus to make sure the calendar was updated. It was also built as a date picker, not a day picker. Your use case is not something I ever had a need to address.

If you put together a PR to solve this, I'd welcome it, but since this is an edge case from a usage I never intended for the library, it's not something I'm able to spend the time to correct.

stell commented 6 years ago

I understand. Selecting a range over new years eve is nothing exotic i think. I will see if i can fix it on my side.

Twipped commented 6 years ago

Correct, there's nothing exotic about selecting a range over new years eve, when you're tracking the year. I never expected someone to not be tracking years. That's just not a use case I planned for.

stell commented 6 years ago

What do you mean by "tracking" ? Using the format: 'DD.MMM' ? I would think every human readable format should work. Its a field for humans after all. Re-parsing it is the problem. So we're going around in circles. Nevermind. If i find something i will post it here.