Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
multiwebinc opened this issue Jun 28, 2016 · 7 comments · May be fixed by #458
Open

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

multiwebinc opened this issue Jun 28, 2016 · 7 comments · May be fixed by #458

Comments

@multiwebinc
Copy link
Contributor

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.

@holtkamp
Copy link
Collaborator

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?

@multiwebinc
Copy link
Contributor Author

@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.

@holtkamp
Copy link
Collaborator

@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!

@shrpne
Copy link

shrpne commented Jul 26, 2016

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

@multiwebinc
Copy link
Contributor Author

multiwebinc commented Jul 26, 2016

@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.

@barryvdh
Copy link

barryvdh commented May 2, 2018

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

@multiwebinc
Copy link
Contributor Author

@bgeree bgeree linked a pull request Oct 3, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants