From 7eaa24e4fc5181a2c78a6b6fa354588553b24d15 Mon Sep 17 00:00:00 2001 From: dyhj625 Date: Tue, 8 Apr 2025 16:16:43 +0900 Subject: [PATCH] =?UTF-8?q?=ED=9C=B4=EA=B0=80=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../localhost/service/localvacaService.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/company/localhost/service/localvacaService.java b/src/main/java/io/company/localhost/service/localvacaService.java index 9682674..7efa145 100644 --- a/src/main/java/io/company/localhost/service/localvacaService.java +++ b/src/main/java/io/company/localhost/service/localvacaService.java @@ -292,34 +292,31 @@ public class localvacaService { * 총 연차 계산 로직 */ public int procCalculateTotalVacation(LocalDate hireDate) { - LocalDate today = LocalDate.now(); // 현재 날짜 - int yearsWorked = hireDate.until(today).getYears(); + LocalDate today = LocalDate.now(); + int currentYear = today.getYear(); + int hireYear = hireDate.getYear(); int hireMonth = hireDate.getMonthValue(); - // 🔹 1년 미만: 입사한 월을 고려하여 연차 개수 계산 - if (yearsWorked < 1) { + // 올해 입사자 → 1년 미만: 입사월 이후로 계산 + if (hireYear == currentYear) { return 12 - hireMonth; - } else { - int totalVacation = 12 - hireMonth; // 1년 미만 사용하고 남은 연차 수 반영 - LocalDate nextIncreaseDate = hireDate.plusYears(1).withMonth(hireMonth).withDayOfMonth(1); - - // 🔹 매년 입사월에 15개 지급 - while (!nextIncreaseDate.isAfter(today)) { - totalVacation += 15; - nextIncreaseDate = nextIncreaseDate.plusYears(1); - } - - // 🔹 입사년도 2년마다 입사월에 15개에서 1개씩 추가 지급 - LocalDate additionalIncreaseDate = hireDate.plusYears(2).withMonth(hireMonth).withDayOfMonth(1); - int extraIncrease = 1; - while (!additionalIncreaseDate.isAfter(today)) { - totalVacation += extraIncrease; - additionalIncreaseDate = additionalIncreaseDate.plusYears(2); - extraIncrease++; // 2년마다 1개씩 증가 - } - - return totalVacation; } + + int totalVacation = 15; + + // 2년 경과 이후부터, 입사월이 도래했을 때 1개씩 추가 + LocalDate baseDate = hireDate.plusYears(2).withDayOfMonth(1); + + while (!baseDate.isAfter(today)) { + // 입사월이 현재 달과 같거나 지났을 때만 연차 추가 + if (baseDate.getYear() == today.getYear() && baseDate.getMonthValue() > today.getMonthValue()) { + break; // 아직 입사월이 도달하지 않았으면 종료 + } + totalVacation += 1; + baseDate = baseDate.plusYears(2); + } + + return totalVacation; } public List selectSentVacationCount(MapDto map) {