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); }