wakirin / Litepicker

Date range picker - lightweight, no dependencies
MIT License
898 stars 132 forks source link

Only display single date if start and end date are the same #306

Open josurzyn opened 2 years ago

josurzyn commented 2 years ago

If the start and end date are the same, it'd be great to have the option only show that date rather than the range.

Eg rather than showing 01/07/22 - 01/07/22, just 01/07/22 would look much neater in a lot of contexts 😎

This would be like the display when maxDays is set to one, but with users still able to select a larger range if they want to.

Context

We have a date picker which defaults to a single day selection, but users can select up to 7 days.

Alternatives

It's probably possible to hack something similar either by comparing dates outside the picker and setting the input value directly, or doing something hacky with the 'format' option, but it'd be much cleaner (and less error prone) to handle this directly inside the picker.

Would be very happy to hear any existing solutions if I've overlooked something 🪄