diff --git a/web/js/datepicker.js.php b/web/js/datepicker.js.php index 6deb9c4489..5f6c272642 100644 --- a/web/js/datepicker.js.php +++ b/web/js/datepicker.js.php @@ -38,10 +38,25 @@ function iPadMobileFix() { ?> function getISODate(year, month, day) { + var date = new Date(Date.UTC(year, month, day)); return date.toISOString().split('T')[0]; } + +// Given a JavaScript Date object returns a date string in YYYY-MM-DD +// format. (Note that toISOString() returns a date in UTC time). +function getLocalISODateString(date) +{ + var month = (date.getMonth() + 1).toString().padStart(2, '0'); + var day = date.getDate().toString().padStart(2, '0'); + var year = date.getFullYear().toString(); + + return [year, month, day].join('-'); +} + + + function weekStart(date, weekStarts) { - var d = new Date(date); + + var d = new Date(date + "T00:00:00"); var diff = d.getDay() - weekStarts; if (diff < 0) { diff += 7; } d.setDate(d.getDate() - diff); - return d.toISOString().split('T')[0]; + return getLocalISODateString(d); } function weekEnd(date, weekStarts) { - var d = new Date(weekStart(date, weekStarts)); + + var d = new Date(weekStart(date, weekStarts) + "T00:00:00"); d.setDate(d.getDate() + 6); - return d.toISOString().split('T')[0]; + return getLocalISODateString(d); } function monthStart(date) { - var d = new Date(date); + + var d = new Date(date + "T00:00:00"); d.setDate(1); - return d.toISOString().split('T')[0]; + return getLocalISODateString(d); } function monthEnd(date) { - var d = new Date(date); + + var d = new Date(date + "T00:00:00"); + var e=new Date(endDate + "T00:00:00"); var hiddenDays = []; and < but not == or === ?> - for (var d=new Date(startDate); !(d>e); d.setDate(d.getDate()+1)) + for (var d=new Date(startDate + "T00:00:00"); !(d>e); d.setDate(d.getDate()+1)) { if (excludeHiddenDays && (hiddenDays.indexOf(d.getDay()) >= 0)) { continue; } - result.push(d.toISOString().split('T')[0]); + result.push(getLocalISODateString(d)); } return result;