Skip to content

Commit b8bcff3

Browse files
authored
Refactor/#91 날씨 가져오기 로직 수정 (#96)
* refactor: #91 날씨에 따른 준비물 표출 로직 수정 * refactor: #91 날씨 가져올 때 타겟 날짜 설정 * refactor: #91 타임존 반영
1 parent ce29a05 commit b8bcff3

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ struct FetchWeatherUseCase: FetchWeatherType {
3131
}
3232

3333
if date > currentDate && DateUtil.isWithinThreeDaysFromToday(startDate: currentDate, endDate: date) {
34-
return try await fetchDayWeather(location: location)
34+
return try await fetchDayWeather(
35+
location: location,
36+
targetDate: date,
37+
timezone: timezone
38+
)
3539
}
3640

3741
return nil
@@ -45,14 +49,24 @@ struct FetchWeatherUseCase: FetchWeatherType {
4549
return .init(weatherCondition: condition, uvIndex: uv)
4650
}
4751

48-
private func fetchDayWeather(location: CLLocation) async throws -> WeatherEntity? {
52+
private func fetchDayWeather(
53+
location: CLLocation,
54+
targetDate: Date,
55+
timezone: String
56+
) async throws -> WeatherEntity? {
4957
let dailyWeather = try await WeatherService.shared.weather(for: location, including: .daily)
50-
guard let dailyFirstWeather = dailyWeather.forecast.first else {
58+
59+
var calendar = Calendar(identifier: .gregorian)
60+
calendar.timeZone = TimeZone(identifier: timezone) ?? .current
61+
62+
guard let targetDayWeather = dailyWeather.forecast.first(where: {
63+
calendar.isDate($0.date, inSameDayAs: targetDate)
64+
}) else {
5165
return nil
5266
}
53-
54-
let condition = dailyFirstWeather.condition
55-
let uv = dailyFirstWeather.uvIndex
67+
68+
let condition = targetDayWeather.condition
69+
let uv = targetDayWeather.uvIndex
5670

5771
return .init(weatherCondition: condition, uvIndex: uv)
5872
}

BeforeGoing/Presentation/Feature/Home/ViewModel/HomeViewModel.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,16 @@ final class HomeViewModel: ViewModeling {
322322
}
323323

324324
private func makeSupplyString(_ weather: WeatherEntity) -> NSMutableAttributedString? {
325-
guard let weatherSupply = weather.weatherCondition.supply,
326-
let uvSupply = weather.uvIndex.supply else {
325+
let supplies = [
326+
weather.weatherCondition.supply,
327+
weather.uvIndex.supply
328+
].compactMap { $0 }
329+
330+
guard !supplies.isEmpty else {
327331
return nil
328332
}
329-
330-
let supplyString = "\(weatherSupply), \(uvSupply)!"
333+
334+
let supplyString = supplies.joined(separator: ", ")
331335
let customedSupplyString = supplyString.customText(
332336
rangedText: supplyString,
333337
color: UIColor.blue700.cgColor

0 commit comments

Comments
 (0)