diff options
author | Tom Smeding <tom@tomsmeding.com> | 2022-03-28 20:03:12 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2022-03-28 21:39:44 +0200 |
commit | baabe0c348009ee32069d79ad1a0febeab17631e (patch) | |
tree | 44b0d7fba1a4597c5995f1a7b62ea2f3f4796817 | |
parent | 78eedbb2aba66695cacac8d832a44512379e4a22 (diff) |
timetrack2: Fix date handling w.r.t. DST
-rw-r--r-- | modules/timetrack2/timetrack.html | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/modules/timetrack2/timetrack.html b/modules/timetrack2/timetrack.html index 209458d..1925a26 100644 --- a/modules/timetrack2/timetrack.html +++ b/modules/timetrack2/timetrack.html @@ -54,10 +54,14 @@ function daystart(date){ return new Date(date.getFullYear(), date.getMonth(), date.getDate()); } +function shiftdays(date, off) { + var d = new Date(date); + d.setDate(d.getDate() + off); + return d; +} + function weekstart(date){ - var d=daystart(date); - var wkday=(d.getDay()+6)%7; - return new Date(d - wkday*24*3600*1000); + return shiftdays(daystart(date), -(date.getDay() + 6) % 7); } var monthnames=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; @@ -199,7 +203,7 @@ function refreshcalendar(list,npreweeks){ var now = new Date(); var today = daystart(now), thismonday = weekstart(now); for (var wkoff = -npreweeks; wkoff <= 1; wkoff++) { - var monday = new Date(thismonday.getTime() + wkoff*7*24*3600*1000); + var monday = shiftdays(thismonday, wkoff * 7); tr = document.createElement("tr"); td = document.createElement("td"); @@ -211,7 +215,7 @@ function refreshcalendar(list,npreweeks){ tr.appendChild(td); for (var i = 0; i < 7; i++) { - var day = new Date(thismonday.getTime() + (wkoff*7+i)*24*3600*1000); + var day = shiftdays(thismonday, wkoff * 7 + i); var tm = hist.get(datekey(day)) || 0; var descr = Math.round(tm/1000/3600*10)/10 + "h"; var target = (day.getDay()+6)%7 < 5 ? 38/5 - 1 : 0; |