From 6435c751b7d24d40376c5841fdb9cdc9d1883687 Mon Sep 17 00:00:00 2001 From: campbell-m <87438215+campbell-m@users.noreply.github.com> Date: Fri, 1 Sep 2023 07:32:27 +0100 Subject: [PATCH 1/4] Fix problem with getting ISO Date strings in timezones other than UTC. --- web/js/datepicker.js.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/web/js/datepicker.js.php b/web/js/datepicker.js.php index 6b118159b0..d96ffb42e8 100644 --- a/web/js/datepicker.js.php +++ b/web/js/datepicker.js.php @@ -42,6 +42,27 @@ function getISODate(year, month, day) return date.toISOString().split('T')[0]; } + +function getLocalISODateString(date) +{ + var month = (date.getMonth() + 1).toString(); + var day = date.getDate().toString(); + var year = date.getFullYear().toString(); + + if (month.length < 2) + { + month = '0' + month; + } + if (day.length < 2) + { + day = '0' + day; + } + + return [year, month, day].join('-'); +} + + + Date: Fri, 1 Sep 2023 08:06:26 +0100 Subject: [PATCH 2/4] Add comments --- web/js/datepicker.js.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/js/datepicker.js.php b/web/js/datepicker.js.php index 66c5edd2ef..d7adc2bffc 100644 --- a/web/js/datepicker.js.php +++ b/web/js/datepicker.js.php @@ -38,11 +38,14 @@ 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(); From 7275c1b77f2938ef4168d42bdf9f59f56d98db18 Mon Sep 17 00:00:00 2001 From: campbell-m <87438215+campbell-m@users.noreply.github.com> Date: Sat, 2 Sep 2023 06:23:24 +0100 Subject: [PATCH 3/4] Simplify code --- web/js/datepicker.js.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/web/js/datepicker.js.php b/web/js/datepicker.js.php index d7adc2bffc..b6b622fd77 100644 --- a/web/js/datepicker.js.php +++ b/web/js/datepicker.js.php @@ -48,19 +48,10 @@ function getISODate(year, month, day) // format. (Note that toISOString() returns a date in UTC time). function getLocalISODateString(date) { - var month = (date.getMonth() + 1).toString(); - var day = date.getDate().toString(); + var month = (date.getMonth() + 1).toString().padStart(2, '0'); + var day = date.getDate().toString().padStart(2, '0'); var year = date.getFullYear().toString(); - if (month.length < 2) - { - month = '0' + month; - } - if (day.length < 2) - { - day = '0' + day; - } - return [year, month, day].join('-'); } From 349ee9c91e02711fcea5db293e8cd8564c407073 Mon Sep 17 00:00:00 2001 From: campbell-m <87438215+campbell-m@users.noreply.github.com> Date: Mon, 11 Sep 2023 05:23:02 -1000 Subject: [PATCH 4/4] Fix properly. --- web/js/datepicker.js.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/web/js/datepicker.js.php b/web/js/datepicker.js.php index b6b622fd77..5f6c272642 100644 --- a/web/js/datepicker.js.php +++ b/web/js/datepicker.js.php @@ -66,7 +66,13 @@ function getLocalISODateString(date) ?> 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) { @@ -77,19 +83,22 @@ function weekStart(date, weekStarts) { } 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 getLocalISODateString(d); } function monthStart(date) { - var d = new Date(date); + + var d = new Date(date + "T00:00:00"); d.setDate(1); 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)) {