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

πŸ› fix: dailyWeather μ‹œκ°„ λ³€ν™˜ 둜직 μˆ˜μ • #151

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading