jquery-date-range-picker icon indicating copy to clipboard operation
jquery-date-range-picker copied to clipboard

Add an option to configure how the number of days is calculated

Open multiwebinc opened this issue 9 years ago • 7 comments

Suppose we have the range 15.06.2016 23:59 ~ 16.06.2016 00:00. The length of time between the start and the end is only 1 second, however this library displays "2 days" because it spans across 2 separate calendar dates. I suggest adding a way to configure this.

Configuration option: daysMode('span' / 'nights' / 'period')

if (daysMode === 'span') {
    // Use the current behavior (default)
}
if (daysMode === 'nights') {
    // Should be the same as the current behavior minus 1. This is the number of
    // times the boundary between 23:59 and 00:00 is crossed
}
if (daysMode === 'period') {
    // The actual number of complete 24 hour periods between one datetime and 
    // another.
    // If we have Monday at 23:59 until Tuesday at 23:58 this should be 0, even 
    // though it crosses from one day to another.
}

I haven't looked at the code, but I can't see this being overly difficult to achieve. If you are interested let me know and I'll code it and submit a pull request.

multiwebinc avatar Jun 28 '16 19:06 multiwebinc

Mm, interesting, but might become potentially complex? Can you give a use case on "when" this would be usefull?

@longbill, what is your stance on this?

holtkamp avatar Jun 29 '16 07:06 holtkamp

@holtkamp For example in the "Typical usage, hotel booking" example on http://longbill.github.io/jquery-date-range-picker/, you typically select the check in and check out dates, so if I check in on the 3rd and check out the 4th I would expect it to say 1 instead of 2. I can edit the locale to say "nights" instead of "days". Having it display "2 days" to me is confusing. Anyway, this is how I'm currently doing it:

hoveringTooltip: function(days) {
    nights = days-1;
    if (nights === 0) {
        return "Select check out";
    }
    if (nights === 1) {
        return '1 night';
    }
    return nights + ' nights';

As for the "period" example, I can't really think of a use case, but if we're going to allow it to be configured, we might as well as there could be somebody who wants to do it like that.

multiwebinc avatar Jun 29 '16 07:06 multiwebinc

@multiwebinc, mm, yeah, the "hotel booking" seems useful indeed. In case you got time and energy to work on a PR and some examples would be great!

holtkamp avatar Jun 29 '16 07:06 holtkamp

I think it is better to impliment in hoveringTooltip function, than make plugin more complex.

shrpne avatar Jul 26 '16 13:07 shrpne

@holtkamp Actually yeah. After seeing how easy it was to edit the tooltip I actually agree with @shrpne. It's probably best not to make the plugin too bloated for a feature that (probably) won't be used that much. However I could work on a PR if you wish when I get time since I can't see it being that hard, or maybe just close this ticket.

multiwebinc avatar Jul 26 '16 16:07 multiwebinc

@multiwebinc Thank you for your example! Did you also find how to change the selected-days text on top?

barryvdh avatar May 02 '18 14:05 barryvdh

@barryvdh Could be as easy as setting a custom language, like https://github.com/longbill/jquery-date-range-picker/blob/31d1eafe296816b7639fd2e91e8ca23c8775e187/demo.js.

multiwebinc avatar May 02 '18 17:05 multiwebinc