Skip to content

Commit

Permalink
Use moment to calculate the difference between dates (#423)
Browse files Browse the repository at this point in the history
* Use moment to calculate the difference between dates

* Get absolute value of the difference, because start_date could come after end_date

* Remove unused functions
  • Loading branch information
calebcauthon authored and holtkamp committed Apr 4, 2018
1 parent 23cbf1f commit 90d3734
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/jquery.daterangepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@
}

function countDays(start, end) {
return Math.abs(daysFrom1970(start) - daysFrom1970(end)) + 1;
return Math.abs(moment(start).diff(moment(end), 'd')) + 1;
}

function setDateRange(date1, date2, silent) {
Expand Down Expand Up @@ -2393,18 +2393,6 @@
return attrString;
}

function daysFrom1970(t) {
return Math.floor(toLocalTimestamp(t) / 86400000);
}

function toLocalTimestamp(t) {
if (moment.isMoment(t)) t = t.toDate().getTime();
if (typeof t == 'object' && t.getTime) t = t.getTime();
if (typeof t == 'string' && !t.match(/\d{13}/)) t = moment(t, opt.format).toDate().getTime();
t = parseInt(t, 10) - new Date().getTimezoneOffset() * 60 * 1000;
return t;
}

function createMonthHTML(d) {
var days = [];
d.setDate(1);
Expand Down

0 comments on commit 90d3734

Please sign in to comment.