diff --git a/changelog.txt b/changelog.txt index df6291106..67f7058b2 100644 --- a/changelog.txt +++ b/changelog.txt @@ -8,6 +8,7 @@ - Fix: [#211] Adjusted preferences window size to fit the whole content - Fix: [#233] Fixes crash when opening the waiver for a day - Fix: [#229] Count Today in totals no longer causes problem in the month balance +- Fix: [#232] Total bar not updating on day change - Fix: [#239] Punch button is disabled when current day is waived - Fix: [#240] Waiver using electron dialog instead of js confirm/alert - Fix: [#244] Waiver opens with filled date when clicking from calendar diff --git a/js/classes/Calendar.js b/js/classes/Calendar.js index 643c30547..965ca0df5 100644 --- a/js/classes/Calendar.js +++ b/js/classes/Calendar.js @@ -404,6 +404,19 @@ class Calendar { this._draw(); } + /** + * Every day change, if the calendar is showing the same month as that of the previous day, + * this function is called to redraw the calendar. + * @param {int} oldDayDate not used in MonthCalendar, just DayCalendar + * @param {int} oldMonthDate + * @param {int} oldYearDate + */ + refreshOnDayChange(oldDayDate, oldMonthDate, oldYearDate) { + if (this._getCalendarMonth() === oldMonthDate && this._getCalendarYear() === oldYearDate) { + this._goToCurrentDate(); + } + } + /* * Display next month. */ @@ -1119,6 +1132,20 @@ class DayCalendar extends Calendar { } } + /** + * Every day change, if the calendar is showing the same date as that of the previous date, + * this function is called to redraw the calendar. + * @param {int} oldDayDate + * @param {int} oldMonthDate + * @param {int} oldYearDate + */ + refreshOnDayChange(oldDayDate, oldMonthDate, oldYearDate) { + let date = new Date(oldYearDate, oldMonthDate, oldDayDate); + if (this._isCalendarOnDate(date)) { + this._goToCurrentDate(); + } + } + /* * Updates the monthly time balance. */ diff --git a/main.js b/main.js index f46ffad1f..921b9e393 100644 --- a/main.js +++ b/main.js @@ -113,9 +113,12 @@ function refreshOnDayChange() { var today = new Date(); if (today > launchDate) { + let oldDate = launchDate.getDate(); + let oldMonth = launchDate.getMonth(); + let oldYear = launchDate.getFullYear(); launchDate = today; // Reload only the calendar itself to avoid a flash - win.webContents.executeJavaScript('calendar.redraw()'); + win.webContents.executeJavaScript(`calendar.refreshOnDayChange(${oldDate},${oldMonth},${oldYear})`); } }