Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ refactor: 챌린지 성공 로직 수정 #190

Merged
merged 9 commits into from
Jan 14, 2025
Prev Previous commit
Next Next commit
♻️ refactor: 챌린지 성공 API 수정
챌린지 성공 API 수정(ChallengeSuccess 클래스 생성)
  • Loading branch information
DongJun1110 committed Jan 14, 2025
commit f0051b1e41bfd82c82230768bd6f38ba9139d8a1
27 changes: 23 additions & 4 deletions src/main/java/foregg/foreggserver/util/DateUtil.java
Original file line number Diff line number Diff line change
@@ -302,12 +302,31 @@ public static String getElapsedTime(LocalDateTime pastTime) {
}
}

public static String getFirstDayOfWeek() {
public static String getFirstDayOfWeek(String firstDate) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 원하는 형식
LocalDate today = LocalDate.now(); // 현재 날짜
LocalDate firstDayOfWeek = today.with(TemporalAdjusters.previousOrSame(java.time.DayOfWeek.SUNDAY)); // 이번 주의 첫 번째 날
LocalDate localDate = toLocalDate(firstDate);
LocalDate afterWeek = localDate.plusWeeks(1);
if (today.equals(afterWeek) || today.isAfter(afterWeek)) {
return afterWeek.format(formatter);
}
return localDate.format(formatter);
}

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // 원하는 형식
return firstDayOfWeek.format(formatter); // 포맷팅된 날짜 반환
public static List<String> getIntervalDates(String firstDate) {
LocalDate localDate = toLocalDate(firstDate);
LocalDate today = LocalDate.now();

// 결과를 저장할 리스트
List<String> intervalDates = new ArrayList<>();

// localDate부터 today까지의 날짜를 순회하며 리스트에 추가
while (!localDate.isAfter(today)) {
intervalDates.add(localDate.toString()); // LocalDate를 String으로 변환
localDate = localDate.plusDays(1); // 하루씩 증가
}

return intervalDates;
}

}