From 2737119ba99cb322ab53c3e6422539404f0c6f9e Mon Sep 17 00:00:00 2001 From: seheonnn Date: Fri, 5 Jul 2024 20:01:34 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20dailyWeather=20=EC=8B=9C?= =?UTF-8?q?=EA=B0=84=20=EB=B3=80=ED=99=98=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeatherTestController.java | 12 ++++++++++++ .../weatherservice/service/WeatherService.java | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/weather-service/src/main/java/com/waither/weatherservice/controller/WeatherTestController.java b/weather-service/src/main/java/com/waither/weatherservice/controller/WeatherTestController.java index 9aaa43e9..4a92c8ef 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/controller/WeatherTestController.java +++ b/weather-service/src/main/java/com/waither/weatherservice/controller/WeatherTestController.java @@ -2,7 +2,9 @@ import java.io.IOException; import java.net.URISyntaxException; +import java.time.LocalDateTime; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -15,7 +17,9 @@ import com.waither.weatherservice.service.WeatherService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/weather-test") @@ -47,4 +51,12 @@ public void airKoreaTest(@RequestBody AirTestRequest request) throws URISyntaxEx public void accuweatherTest(@RequestBody AccuweatherTestRequest request) throws URISyntaxException, IOException { weatherService.convertLocation(request.latitude(), request.longitude()); } + + @GetMapping("/converㅅ") + public LocalDateTime convertTest() { + + LocalDateTime specificDateTime = LocalDateTime.of(2024, 7, 5, 23, 0); + log.info("Changed : {}", specificDateTime); + return weatherService.convertLocalDateTimeToDailyWeatherTime(specificDateTime); + } } diff --git a/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java b/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java index f8b75b5f..1252f9e5 100644 --- a/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java +++ b/weather-service/src/main/java/com/waither/weatherservice/service/WeatherService.java @@ -173,7 +173,7 @@ public MainWeatherResponse getMainWeather(double latitude, double longitude) { String expectedWeatherKey = regionName + "_" + convertLocalDateTimeToString(now); - LocalDateTime dailyWeatherBaseTime = convertLocalDateTimeToDailyWeatherTime(now); + LocalDateTime dailyWeatherBaseTime = convertLocalDateTimeToDailyWeatherTime(now.minusHours(1)); String dailyWeatherKey = regionName + "_" + convertLocalDateTimeToString(dailyWeatherBaseTime); @@ -219,14 +219,15 @@ public String convertLocalDateTimeToString(LocalDateTime time) { public LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) { // DailyWeather 정보는 3시간마다 - List scheduledHours = Arrays.asList(2, 5, 8, 11, 14, 17, 20, 23); + List scheduledHours = Arrays.asList(0, 3, 6, 9, 12, 15, 18, 21); int currentHour = time.getHour(); int adjustedHour = scheduledHours.stream() .filter(hour -> hour <= currentHour) .reduce((first, second) -> second) - .orElse(23); + .orElse(scheduledHours.get(scheduledHours.size() - 1)); // 이전 날의 마지막 스케줄 시간(21시) 반환 + // 현재 시간이 첫 스케줄 시간(0시)보다 작을 경우, 전날의 마지막 스케줄 시간으로 설정 if (currentHour < scheduledHours.get(0)) { time = time.minusDays(1); }