Skip to content

Commit

Permalink
Merge branch 'hotfix/finan-last-week' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Oct 29, 2024
2 parents d98c6a0 + cb130f0 commit 694934b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-cct",
"version": "0.13.10",
"version": "0.13.12",
"description": "",
"author": "",
"private": true,
Expand Down
30 changes: 21 additions & 9 deletions src/utils/payment-date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
endOfDay,
isFriday,
isSameMonth,
isSameYear,
isThursday,
nextFriday,
previousFriday,
Expand Down Expand Up @@ -249,19 +250,30 @@ function getFirstLastFridays(
r.endDate = previousFriday(r.endDate);
}

// Remover semanas do futuro
const today = new Date();
/** Pega de qui-qua */
const thisFriday = isThursday(today)
? addDays(today, 8)
: nextFriday(today);
if (r.endDate > thisFriday) {
r.endDate = thisFriday;
}
r.endDate = removeFutureWeeks(r.endDate);
r.endDate = validateLastMonthWeek(r.endDate, timeInterval);
}
return r;
}

function removeFutureWeeks(endDate: Date) {
let newEndDate = endDate;
const today = new Date();
/** Pega de qui-qua */
const thisFriday = isThursday(today) ? addDays(today, 8) : nextFriday(today);
if (newEndDate > thisFriday) {
newEndDate = thisFriday;
}
return newEndDate;
}

function validateLastMonthWeek(friday: Date, timeInterval?: TimeIntervalEnum) {
const isLastMonth = timeInterval === TimeIntervalEnum.LAST_MONTH;
const isLastWeek = !isSameMonth(friday, nextFriday(friday));
const isCurrentYearMonth = isSameYear(friday, new Date()) && isSameMonth(friday, new Date());
return isLastMonth && isLastWeek && isCurrentYearMonth ? nextFriday(friday) : friday;
}

export function validateDate(
startDateStr?: string,
endDateStr?: string,
Expand Down

0 comments on commit 694934b

Please sign in to comment.