I resolved my Timezone issue with the following code corrections, marked below the [Commented Code] ::
Best regards,
jim_k
import Foundation
import SwiftUI
import CoreLocation
import WeatherKit
struct TestForecastView: View {
//let dailyForecast: Forecast<DayWeather>
let dayWeatherList: [DayWeather]
let timezone: TimeZone
var body: some View {
Spacer()
.frame(height: 10)
Text("Sunrise Sunset")
.font(.system(size: 24, weight: .bold))
.foregroundStyle(.white)
Text("Ten Day Forecast")
.font(.system(size: 11, weight: .medium))
.foregroundStyle(.white)
Spacer()
.frame(height: 4)
VStack {
//ForEach(dailyForecast, id: \.date) { day in
ForEach(dayWeatherList, id: \.date) { dayWeatherItem in
LabeledContent {
HStack(spacing: 20) {
RoundedRectangle(cornerRadius: 10)
.fill(Color.orange.opacity(0.5))
.frame(width: 120, height: 5)
.padding(.leading, 2)
.padding(.trailing, 0)
VStack {
Image(systemName: "sunrise")
.font(.system(size: 24.0, weight: .bold))
.foregroundColor(.yellow)
//Text(day.sun.sunrise?.formatted(.dateTime.hour().minute()) ?? "?")
Text(dayWeatherItem.sun.sunrise?.localTime(for: timezone) ?? "?")
.font(.system(size: 10.0))
}
.frame(width: 50, height: 20)
VStack {
Image(systemName: "sunset")
.font(.system(size: 24.0, weight: .bold))
.foregroundColor(.yellow)
//Text(day.sun.sunset?.formatted(.dateTime.hour().minute()) ?? "?")
Text(dayWeatherItem.sun.sunset?.localTime(for: timezone) ?? "?"
.font(.system(size: 10.0))
}
.frame(width: 50, height: 20)
Spacer()
.frame(width: 2)
}
} label: {
//Text(day.date.localWeekDayShort(for: timezone))
Text(dayWeatherItem.date.localDate(for: timezone))
.frame(width: 80, alignment: .leading)
.padding(.leading, 30)
.padding(.trailing, 0)
}
.frame(width: 380, height: 52)
.background(RoundedRectangle(cornerRadius: 4).fill(LinearGradient(gradient: Gradient(colors: [Color(.systemBlue), Color(.black)]), startPoint: .topLeading, endPoint: .bottomTrailing)).stroke(.black, lineWidth: 6).multilineTextAlignment(.center))
.shadow(color: Color.white.opacity(0.1), radius: 4, x: -2, y: -2)
.shadow(color: Color.white.opacity(0.1), radius: 4, x: 2, y: 2)
}
}
.padding(.top, 20)
.padding(.bottom, 20)
.padding(.leading, 20)
.padding(.trailing, 20)
.contentMargins(.all, 4, for: .scrollContent)
.background(RoundedRectangle(cornerRadius: 10).fill(Color.black.opacity(0.0)).stroke(.gray, lineWidth: 4))
} // End of [var body: some View]
} // End of [struct TestForecastView: View]
The revised Paris Sunrise and Sunset displays the correct times :
As a side note, changing the [sun.sunrise?] to [moon.moonrise?] and [sun.sunset?] to [moon.moonset?] affects the Moon Phase too ... :]
Paris Sunrise Sunset ::
Paris Moonrise Moonset ::