Skip to content

Commit 7cab261

Browse files
authored
Merge pull request #57 from ChillCoders-CapstoneDesign/feature/notification
refactor: 디데이 계산 로직 수정
2 parents 8f4459a + a529b2b commit 7cab261

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/main/java/com/project/submate/subscribe/service/SubscribeService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ public SubscribeListResponseDto subscribeAllList() {
5555
// 디데이 계산(******Asia/Seoul 시간으로 나오지 않아서 임의로 결과에 -1을 해주었다)
5656
private int calculateDday(LocalDate startDate) {
5757
// LocalDate.plusMonths: 자동으로 월의 마지막 날짜를 고려하여 계산한다.
58-
LocalDate baseDate = startDate.plusMonths(1); // 기준일: startDate + 1달
58+
// LocalDate baseDate = startDate.plusMonths(1); // 기준일: startDate + 1달
5959
LocalDate now = LocalDate.now(ZoneId.of("Asia/Seoul"));
60-
int dDay = (int) ChronoUnit.DAYS.between(now, baseDate);
60+
61+
// 반복 결제일: 매달 startDate의 day에 결제된다고 가정한다.
62+
LocalDate nextBillingDate = startDate;
63+
64+
// 현재 날짜 이후의 가장 가까운 결제일을 찾는다.
65+
while (!nextBillingDate.isAfter(now)) {
66+
nextBillingDate = nextBillingDate.plusMonths(1);
67+
}
68+
int dDay = (int) ChronoUnit.DAYS.between(now, nextBillingDate);
6169
return Math.max(dDay, 0); // 음수 방지
6270
}
6371

0 commit comments

Comments
 (0)