Files
Tempestas/Packages/TempestasInfrastructure/Tests/TempestasInfrastructureTests/OpenMeteoDateDecodingTests.swift
T
2026-08-09 11:10:09 -04:00

42 lines
1.4 KiB
Swift

import Foundation
@testable import TempestasInfrastructure
import Testing
@Suite struct OpenMeteoDateDecodingTests {
private static let json = """
{
"latitude": 35.7,
"longitude": 139.7,
"timezone": "Asia/Tokyo",
"daily": {
"time": ["2024-06-01"],
"dew_point_2m_max": [15.0],
"relative_humidity_2m_min": [50.0],
"sunrise": ["2024-06-01T04:25"],
"sunset": ["2024-06-01T18:52"],
"surface_pressure_min": [1008.0],
"apparent_temperature_max": [26.0],
"uv_index_max": [7.0],
"visibility_mean": [12000.0],
"weather_code": [0],
"wind_direction_10m_dominant": [90],
"wind_gusts_10m_min": [10.0],
"wind_speed_10m_min": [8.0]
}
}
"""
@Test func decodesTruncatedIso8601SunriseInRequestedTimeZone() throws {
let timeZone = try #require(TimeZone(identifier: "Asia/Tokyo"))
let decoder = OpenMeteoDateDecoding.decoder(timeZone: timeZone)
let contract = try decoder.decode(WeatherApiResponseContract.self, from: Data(Self.json.utf8))
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = timeZone
let components = calendar.dateComponents([.hour, .minute], from: contract.items.sunriseTimes[0])
#expect(components.hour == 4)
#expect(components.minute == 25)
}
}