Skip to content

Commit

Permalink
fix (#4) : 알고리즘 오류 수정 , dday 잘못계산
Browse files Browse the repository at this point in the history
  • Loading branch information
daehwan2yo committed Apr 12, 2022
1 parent 51eb8bf commit ef673e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.persistence.OneToOne;

import com.codingwasabi.howtodo.web.account.entity.Account;
import com.codingwasabi.howtodo.web.policy.util.DateProcessor;

import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -44,8 +45,7 @@ private Exam(Account account, String name, LocalDateTime dueDateTime, int studyD
}

public int getDDay(LocalDate today) {
return today.until(dueDateTime.toLocalDate())
.getDays();
return DateProcessor.calculateDDay(today, dueDateTime.toLocalDate());
}

public boolean isMid() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codingwasabi.howtodo.web.policy.planMaking;

import static com.codingwasabi.howtodo.web.policy.util.ExamDateSorting.*;
import static com.codingwasabi.howtodo.web.policy.util.DateProcessor.*;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.codingwasabi.howtodo.web.policy.tendency;

import static com.codingwasabi.howtodo.web.policy.util.ExamDateSorting.*;
import static com.codingwasabi.howtodo.web.policy.util.DateProcessor.*;

import java.time.LocalDate;
import java.util.Collections;
Expand Down Expand Up @@ -121,16 +121,15 @@ private boolean everyExamHasIntervalOnlyOneDay(List<Exam> sortedExams) {
LocalDate beforeDay = null;

for (Exam exam : sortedExams) {
LocalDate examDate = exam.getDueDateTime()
.toLocalDate();

if (beforeDay == null) {
beforeDay = exam.getDueDateTime()
.toLocalDate();
beforeDay = examDate;
continue;
}

if (Math.abs(exam.getDueDateTime()
.toLocalDate()
.until(beforeDay)
.getDays()) != 1) {
if (calculateDDay(beforeDay, examDate) != 1) {
return false;
}
beforeDay = exam.getDueDateTime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.stream.Collectors;

import com.codingwasabi.howtodo.web.dailyplan.entity.DailyPlan;
import com.codingwasabi.howtodo.web.exam.entity.Exam;

public class ExamDateSorting {
public class DateProcessor {
public static List<Exam> sortExams(List<Exam> exams) {
return exams.stream()
.sorted((e1, e2) -> {
Expand Down Expand Up @@ -38,4 +39,8 @@ public static List<DailyPlan> sortDailyPlans(List<DailyPlan> dailyPlans) {
})
.collect(Collectors.toList());
}

public static int calculateDDay(LocalDate start, LocalDate end) {
return (int)ChronoUnit.DAYS.between(start, end);
}
}

0 comments on commit ef673e0

Please sign in to comment.