From ef673e0e5e51c29a40f3df4cc67c9beb90493c8d Mon Sep 17 00:00:00 2001 From: mac_daehwan2yo Date: Tue, 12 Apr 2022 10:09:33 +0900 Subject: [PATCH] =?UTF-8?q?fix=20(#4)=20:=20=EC=95=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EC=A6=98=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20,=20dday?= =?UTF-8?q?=20=EC=9E=98=EB=AA=BB=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codingwasabi/howtodo/web/exam/entity/Exam.java | 4 ++-- .../policy/planMaking/MonthPlanMakingPolicy.java | 2 +- .../policy/tendency/MostChosenTendencySolution.java | 13 ++++++------- .../{ExamDateSorting.java => DateProcessor.java} | 7 ++++++- 4 files changed, 15 insertions(+), 11 deletions(-) rename src/main/java/com/codingwasabi/howtodo/web/policy/util/{ExamDateSorting.java => DateProcessor.java} (85%) diff --git a/src/main/java/com/codingwasabi/howtodo/web/exam/entity/Exam.java b/src/main/java/com/codingwasabi/howtodo/web/exam/entity/Exam.java index fc0caa4..9b809dd 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/exam/entity/Exam.java +++ b/src/main/java/com/codingwasabi/howtodo/web/exam/entity/Exam.java @@ -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; @@ -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() { diff --git a/src/main/java/com/codingwasabi/howtodo/web/policy/planMaking/MonthPlanMakingPolicy.java b/src/main/java/com/codingwasabi/howtodo/web/policy/planMaking/MonthPlanMakingPolicy.java index 7a5459d..69d7f62 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/policy/planMaking/MonthPlanMakingPolicy.java +++ b/src/main/java/com/codingwasabi/howtodo/web/policy/planMaking/MonthPlanMakingPolicy.java @@ -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; diff --git a/src/main/java/com/codingwasabi/howtodo/web/policy/tendency/MostChosenTendencySolution.java b/src/main/java/com/codingwasabi/howtodo/web/policy/tendency/MostChosenTendencySolution.java index b127b31..9992c1b 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/policy/tendency/MostChosenTendencySolution.java +++ b/src/main/java/com/codingwasabi/howtodo/web/policy/tendency/MostChosenTendencySolution.java @@ -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; @@ -121,16 +121,15 @@ private boolean everyExamHasIntervalOnlyOneDay(List 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() diff --git a/src/main/java/com/codingwasabi/howtodo/web/policy/util/ExamDateSorting.java b/src/main/java/com/codingwasabi/howtodo/web/policy/util/DateProcessor.java similarity index 85% rename from src/main/java/com/codingwasabi/howtodo/web/policy/util/ExamDateSorting.java rename to src/main/java/com/codingwasabi/howtodo/web/policy/util/DateProcessor.java index 4eeb3c1..0aebe03 100644 --- a/src/main/java/com/codingwasabi/howtodo/web/policy/util/ExamDateSorting.java +++ b/src/main/java/com/codingwasabi/howtodo/web/policy/util/DateProcessor.java @@ -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 sortExams(List exams) { return exams.stream() .sorted((e1, e2) -> { @@ -38,4 +39,8 @@ public static List sortDailyPlans(List dailyPlans) { }) .collect(Collectors.toList()); } + + public static int calculateDDay(LocalDate start, LocalDate end) { + return (int)ChronoUnit.DAYS.between(start, end); + } }