Skip to content

Commit

Permalink
All time balance target dates for Month and Day Calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoarthur0 committed Aug 6, 2020
1 parent 3c9ff93 commit 8970a48
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions js/classes/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ class Calendar {
this._draw();
}

_updateAllTimeBalance() {
var targetYear = this._getCalendarYear(),
/**
* Returns a date object for which the all time balance will be calculated.
* If current month, returns the actual day. If not, first day of following month.
* @return {Date}
*/
_getTargetDayForAllTimeBalance() {
let targetYear = this._getCalendarYear(),
targetMonth = this._getCalendarMonth(),
// If we are not displaying the current month we need to compute the balance including the
// last day of the month. To do so we move to the first day of the following month
Expand All @@ -97,6 +102,11 @@ class Calendar {
if (isCurrentMonth && this._getCountToday()) {
targetDate.setDate(targetDate.getDate() + 1);
}
return targetDate;
}

_updateAllTimeBalance() {
const targetDate = this._getTargetDayForAllTimeBalance();
computeAllTimeBalanceUntilAsync(targetDate).then(balance => {
var balanceElement = $('#overall-balance');
if (balanceElement) {
Expand Down Expand Up @@ -1255,6 +1265,20 @@ class DayCalendar extends Calendar {

this._updateLeaveBy();
}

/**
* Returns a date object for which the all time balance will be calculated.
* For DayCalendar, it's the day of CalendarDate => the day being displayed.
* If "count_today" is active, the following day.
* @return {Date}
*/
_getTargetDayForAllTimeBalance() {
let targetDate = new Date(this._getCalendarYear(), this._getCalendarMonth(), this._getCalendarDate());
if (this._getCountToday()) {
targetDate.setDate(targetDate.getDate() + 1);
}
return targetDate;
}
}

module.exports = {
Expand Down

0 comments on commit 8970a48

Please sign in to comment.