File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -190,10 +190,12 @@ extension WeatherLocation {
190190
191191extension CurrentWeather {
192192 init ( dto: CurrentWeatherDTO ) throws {
193- guard ( 0 ..< 360 ) . contains ( dto. windDirectionDegrees) else {
193+ guard ( 0 ... 360 ) . contains ( dto. windDirectionDegrees) else {
194194 throw WeatherDTOMappingError . invalidWindDirection ( dto. windDirectionDegrees)
195195 }
196196
197+ let windDirectionDegrees = dto. windDirectionDegrees == 360 ? 0 : dto. windDirectionDegrees
198+
197199 self . init (
198200 id: dto. id,
199201 temperatureC: dto. temperatureC,
@@ -209,7 +211,7 @@ extension CurrentWeather {
209211 uvIndex: dto. uvIndex,
210212 uvCategory: UVIndexCategory ( dto: dto. uvCategory) ,
211213 windKph: dto. windKph,
212- windDirection: WindDirection ( degrees: dto . windDirectionDegrees) ,
214+ windDirection: WindDirection ( degrees: windDirectionDegrees) ,
213215 humidity: dto. humidity,
214216 visibilityKilometers: dto. visibilityKilometers,
215217 pressureMillibars: dto. pressureMillibars,
Original file line number Diff line number Diff line change @@ -189,6 +189,35 @@ struct WeatherTests {
189189 }
190190 }
191191
192+ @Test func windDirection360MapsToNorth( ) throws {
193+ let dto = CurrentWeatherDTO (
194+ id: " north-wind " ,
195+ temperatureC: 10 ,
196+ highC: 12 ,
197+ lowC: 8 ,
198+ feelsLikeC: 9 ,
199+ condition: . sunny,
200+ solarProgress: SolarDayProgressDTO ( kind: . daylight, daylightFraction: 0.5 ) ,
201+ sunrise: LocalClockTimeDTO ( hour: 6 , minute: 0 ) ,
202+ sunset: LocalClockTimeDTO ( hour: 18 , minute: 0 ) ,
203+ airQualityIndex: 10 ,
204+ airQualityCategory: . good,
205+ uvIndex: 1 ,
206+ uvCategory: . low,
207+ windKph: 12 ,
208+ windDirectionDegrees: 360 ,
209+ humidity: 50 ,
210+ visibilityKilometers: 10 ,
211+ pressureMillibars: 1_013 ,
212+ pressureTrend: . steady,
213+ precipChance: 0
214+ )
215+
216+ let current = try CurrentWeather ( dto: dto)
217+
218+ #expect( current. windDirection == WindDirection ( degrees: 0 ) )
219+ }
220+
192221 @Test func weatherFixtureDecodesAsExpectedDTO( ) throws {
193222 let decoded : WeatherReportDTO = try decodeFixture ( named: " weather-report-loc-current-san-francisco " )
194223
You can’t perform that action at this time.
0 commit comments