File tree Expand file tree Collapse file tree
Presentation/Feature/Home/ViewModel Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments