question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
multiwebinccommented, Jun 29, 2016

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

0reactions
multiwebinccommented, May 2, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Calculate the Number of Days Between Two Dates in ...
You need to specify the 'Start Date' and the 'End Date' in the Days function, and it will give you the total number...
Read more >
DAYS function - Microsoft Support
This article describes the formula syntax and usage of the DAYS function in Microsoft Excel. ... Description. Returns the number of days between...
Read more >
Calculate number of days between two dates in Excel - Ablebits
Click the Insert formula button and have the formula inserted in the selected cell. Done! Build a formula to calculate days between two...
Read more >
How to calculate the days between two dates? - Formfacade
1. You can subtract the start date from end date to calculate the number of days between the dates. By default, the answer...
Read more >
Add calculated fields to a form - Adobe Support
Formatting Calculated Fields as Dates ; hh. The hour of the day with leading zero if required. "01" to "12" ; H ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found