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

Ability to count number of nights instead of days #458

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,7 @@ <h2 id="configuration">Configuration</h2>
dayTdAttrs: [],
applyBtnClass: '',
singleMonth: 'auto',
hoveringTooltip: function(days, startTime, hoveringTime)
{
return days > 1 ? days + ' ' + lang('days') : '';
},
hoveringTooltip: true,
showTopbar: true,
swapTime: false,
selectForward: false,
Expand Down Expand Up @@ -830,6 +827,10 @@ <h3>You can use the following keys in the configObject to overwrite the default
<i>This number defines the minimum days of the selected range
if this is 0, means do not limit minimum days</i>

<b>dayMode ('days' || 'nights')</b>
<i>Whether to count the nights instead of days in the selected date range. Of you choose 'nights',
you can define a custom language to change the text of the tooltip and the top bar. </i>

<b>maxDays (Number)</b>
<i>This number defines the maximum days of the selected range
if this is 0, means do not limit maximum days</i>
Expand Down Expand Up @@ -883,6 +884,10 @@ <h3>You can use the following keys in the configObject to overwrite the default
in the one month view. If this is set to 'auto', it will be changed to true if the screen width
is lower than 480.</i>

<b>hoveringTooltip (Boolean || Function) Default: true</b>
<i>If true, it will show a tooltip when you select a date range. You can define a callback function
to customize the content of the tooltip.</i>

<b>showDateFilter ( Function(Int time, Int date) )</b>
<i>This is a callback function when creating each date element in the calendar. First paramter will
be the timestamp of that day. Second parameter will be the date of that month.</i>
Expand Down
19 changes: 13 additions & 6 deletions src/jquery.daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@
},
minDays: 0,
maxDays: 0,
dayMode: 'days',
showShortcuts: false,
shortcuts: {
//'prev-days': [1,3,5,7],
Expand All @@ -914,9 +915,7 @@
selectBackward: false,
applyBtnClass: '',
singleMonth: 'auto',
hoveringTooltip: function(days, startTime, hoveringTime) {
return days > 1 ? days + ' ' + translate('days') : '';
},
hoveringTooltip: true,
showTopbar: true,
swapTime: false,
showWeekNumbers: false,
Expand Down Expand Up @@ -1663,8 +1662,12 @@
if (opt.hoveringTooltip) {
if (typeof opt.hoveringTooltip == 'function') {
tooltip = opt.hoveringTooltip(days, opt.start, hoverTime);
} else if (opt.hoveringTooltip === true && days > 1) {
tooltip = days + ' ' + translate('days');
} else if (opt.hoveringTooltip === true) {
if(days > 1) {
tooltip = days + ' ' + translate('days');
} else if (opt.dayMode == 'nights' && days == 1) {
tooltip = days + ' ' + translate('day');
}
}
}
}
Expand Down Expand Up @@ -1835,7 +1838,11 @@
}

function countDays(start, end) {
return Math.abs(moment(start).diff(moment(end), 'd')) + 1;
var days = Math.abs(moment(start).diff(moment(end), 'd'));
if(opt.dayMode != 'nights') {
days++;
}
return days;
}

function setDateRange(date1, date2, silent) {
Expand Down