Skip to content

Commit 90d3734

Browse files
calebcauthonholtkamp
authored andcommitted
Use moment to calculate the difference between dates (#423)
* 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
1 parent 23cbf1f commit 90d3734

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/jquery.daterangepicker.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@
18031803
}
18041804

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

18091809
function setDateRange(date1, date2, silent) {
@@ -2393,18 +2393,6 @@
23932393
return attrString;
23942394
}
23952395

2396-
function daysFrom1970(t) {
2397-
return Math.floor(toLocalTimestamp(t) / 86400000);
2398-
}
2399-
2400-
function toLocalTimestamp(t) {
2401-
if (moment.isMoment(t)) t = t.toDate().getTime();
2402-
if (typeof t == 'object' && t.getTime) t = t.getTime();
2403-
if (typeof t == 'string' && !t.match(/\d{13}/)) t = moment(t, opt.format).toDate().getTime();
2404-
t = parseInt(t, 10) - new Date().getTimezoneOffset() * 60 * 1000;
2405-
return t;
2406-
}
2407-
24082396
function createMonthHTML(d) {
24092397
var days = [];
24102398
d.setDate(1);

0 commit comments

Comments
 (0)