diff --git a/BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift b/BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift index d4cd5f6..d443ea7 100644 --- a/BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift +++ b/BeforeGoing/Domain/UseCase/Weather/FetchtWeatherUseCase.swift @@ -31,7 +31,11 @@ struct FetchWeatherUseCase: FetchWeatherType { } if date > currentDate && DateUtil.isWithinThreeDaysFromToday(startDate: currentDate, endDate: date) { - return try await fetchDayWeather(location: location) + return try await fetchDayWeather( + location: location, + targetDate: date, + timezone: timezone + ) } return nil @@ -45,14 +49,24 @@ struct FetchWeatherUseCase: FetchWeatherType { return .init(weatherCondition: condition, uvIndex: uv) } - private func fetchDayWeather(location: CLLocation) async throws -> WeatherEntity? { + private func fetchDayWeather( + location: CLLocation, + targetDate: Date, + timezone: String + ) async throws -> WeatherEntity? { let dailyWeather = try await WeatherService.shared.weather(for: location, including: .daily) - guard let dailyFirstWeather = dailyWeather.forecast.first else { + + var calendar = Calendar(identifier: .gregorian) + calendar.timeZone = TimeZone(identifier: timezone) ?? .current + + guard let targetDayWeather = dailyWeather.forecast.first(where: { + calendar.isDate($0.date, inSameDayAs: targetDate) + }) else { return nil } - - let condition = dailyFirstWeather.condition - let uv = dailyFirstWeather.uvIndex + + let condition = targetDayWeather.condition + let uv = targetDayWeather.uvIndex return .init(weatherCondition: condition, uvIndex: uv) } diff --git a/BeforeGoing/Presentation/Feature/Home/ViewModel/HomeViewModel.swift b/BeforeGoing/Presentation/Feature/Home/ViewModel/HomeViewModel.swift index 7adc7cc..3528a0a 100644 --- a/BeforeGoing/Presentation/Feature/Home/ViewModel/HomeViewModel.swift +++ b/BeforeGoing/Presentation/Feature/Home/ViewModel/HomeViewModel.swift @@ -322,12 +322,16 @@ final class HomeViewModel: ViewModeling { } private func makeSupplyString(_ weather: WeatherEntity) -> NSMutableAttributedString? { - guard let weatherSupply = weather.weatherCondition.supply, - let uvSupply = weather.uvIndex.supply else { + let supplies = [ + weather.weatherCondition.supply, + weather.uvIndex.supply + ].compactMap { $0 } + + guard !supplies.isEmpty else { return nil } - - let supplyString = "\(weatherSupply), \(uvSupply)!" + + let supplyString = supplies.joined(separator: ", ") let customedSupplyString = supplyString.customText( rangedText: supplyString, color: UIColor.blue700.cgColor