WeatherKit forecast dates - what are they?

I don’t understand what the times are that are returned in forecasts.

guard let (current, hourly, daily) = try? await weatherService.weather(for: location, including: .current, .hourly, .daily(startDate: startDate, endDate: endDate))

I’m expecting this to be the time to which the forecast applies.

let utc = hourly.forecast[hour].date

When I convert it from UTC to local time I get something unusual for localDate

let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "ha"
let localDateString = dateFormatter.string(from: utc)

What are these times? Shouldn’t the hourly be times increasing in one hour increments from startDate? Am I doing something incorrectly? Thanks

Beuller?

Yes, HourWeather.date should be the start of each hour. What are you seeing instead?

Hi, thanks for your response. My question is not whether the date is at the start of the hour.

Shouldn’t the hourly be times increasing in one hour increments from startDate?

I'm seeing times that unconditionally start at 10PM. If I run a query at 7AM I expect the hourly forecast entries to be 8AM, 9AM, etc.

// at 7AM after conversion I expect date to indicate 8AM
let utc = hourly.forecast[0].date

It appears that I am doing something wrong in my conversion Could you please provide a code fragment that would yield dates as I describe? Thanks.

To be clear, I'm setting startDate and endDate like this:

let startDate = Date() let endDate = Calendar.current.date(byAdding: .weekOfYear, value: 1, to: startDate)

I understand, thank you! This is different from other models I'm used to where future whether is an offset from current time. This is equally sensible, just didn't occur to me.

how can I get the hourly weather for a future date? apparently the hourly is only for the current date?

Hourly weather is available for the next ten days. Just specify the startDate and endDate for hourly just as you do for daily:

.hourly(startDate: startDate, endDate: endDate)

See https://developer.apple.com/documentation/weatherkit/weatherquery/hourly for details.

WeatherKit forecast dates - what are they?
 
 
Q