Skip to content

Commit

Permalink
πŸ› fix: dailyWeather μ‹œκ°„ λ³€ν™˜ 둜직 μˆ˜μ •
Browse files Browse the repository at this point in the history
  • Loading branch information
seheonnn authored Jul 5, 2024
2 parents 4c60250 + 2737119 commit 1a14ca9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -219,14 +219,15 @@ public String convertLocalDateTimeToString(LocalDateTime time) {
public LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) {

// DailyWeather μ •λ³΄λŠ” 3μ‹œκ°„λ§ˆλ‹€
List<Integer> scheduledHours = Arrays.asList(2, 5, 8, 11, 14, 17, 20, 23);
List<Integer> 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);
}
Expand Down

0 comments on commit 1a14ca9

Please sign in to comment.