-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
72 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
weather-service/src/main/java/com/waither/weatherservice/utills/DateTimeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.waither.weatherservice.utills; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class DateTimeUtils { | ||
|
||
public static LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) { | ||
|
||
// DailyWeather 정보는 3시간마다 | ||
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(scheduledHours.get(scheduledHours.size() - 1)); // 이전 날의 마지막 스케줄 시간(21시) 반환 | ||
|
||
// 현재 시간이 첫 스케줄 시간(0시)보다 작을 경우, 전날의 마지막 스케줄 시간으로 설정 | ||
if (currentHour < scheduledHours.get(0)) { | ||
time = time.minusDays(1); | ||
} | ||
|
||
return time.withHour(adjustedHour).withMinute(0).withSecond(0).withNano(0); | ||
} | ||
|
||
public static String convertLocalDateTimeToString(LocalDateTime time) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | ||
String formattedDateTime = time.format(formatter); | ||
|
||
String[] lst = formattedDateTime.split(" "); | ||
String baseDate = lst[0].replace("-", ""); | ||
|
||
String[] temp = lst[1].split(":"); | ||
String baseTime = temp[0] + "00"; | ||
|
||
return baseDate + "_" + baseTime; | ||
} | ||
|
||
public static String convertLocalDateToString(LocalDate localDate) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); | ||
return localDate.format(formatter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../waither/weatherservice/gps/LatXLngY.java → ...ither/weatherservice/utills/LatXLngY.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.waither.weatherservice.gps; | ||
package com.waither.weatherservice.utills; | ||
|
||
import lombok.Builder; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters