zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

Bug? Calendar highlights one day prior to selection date #845

Closed apg-dev closed 4 years ago

apg-dev commented 4 years ago

I can't figure out why the calendar widget highlights "yesterday's" date, not today. I see this regardless of which date I click on, the day prior to the one selected gets the “calendar-date-active” class setting. Looking at calendar.js, activeDate seems to be off by -1.

trilium-calendar-highlight active-date-calendar-js
zadam commented 4 years ago

Hello, looks like a bug. What timezone are you in? Wondering if it might be caused by that (for me it works fine but I'm close to GMT ...

apg-dev commented 4 years ago

EST USA (UTC/GMT - 5 hours). Seems to be independent of the time of day.

apg-dev commented 4 years ago

Looks like you're right - it is timezone related.

I wrote the following code to determine the user's local timezone then convert activeDate to GMT. I tested this in my local environment and it works fine.

In /src/public/javascripts/widgets/calendar.js

REPLACE line 44: this.activeDate = new Date(Date.parse(activeDate));

With these four lines:

var activeDateLocal = new Date(activeDate); var tzo = activeDateLocal.getTimezoneOffset(); var activeDateGMT = new Date(activeDateLocal.setMinutes( activeDateLocal.getMinutes() + tzo )); this.activeDate = activeDateGMT;

Let me know if you'd like me to create a formal patch.

apg-dev commented 4 years ago

Your patch is far more elegant and simple than the hack I put together. Thank you for the fix - works great.