Closed IsamZareer closed 1 year ago
@IsamZareer I'm going to guess that your located in a timezone that is 1 hour different from Amman/Istanbul. Our library will provide the correct Date
but when you format and display the date you will be responsible for setting the TimeZone in your DateFormatter based on the location the prayers are for. If you look at the Full Example
in the README you will see that is what we are doing https://github.com/batoulapps/adhan-swift#full-example
i added it to my date formatter and nothing happened
import SwiftUI
import Adhan
private let dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .none
dateFormatter.timeStyle = .medium
dateFormatter.timeZone = TimeZone(identifier: "Europe/Istanbul")
return dateFormatter
}()
struct AthanView3: View {
@State private var times = prayerTimesIstanbul()
@StateObject var locationManager = LocationManager()
var body: some View {
VStack {
PrayerTimeView(times: $times)
.navigationBarTitle("Prayer Times")
}
}
static func prayerTimesIstanbul() -> PrayerTimes? {
let cal = Calendar(identifier: Calendar.Identifier.gregorian)
let date = cal.dateComponents([.year, .month, .day], from: Date())
@State var coordinates = Coordinates(latitude: 41.0082, longitude: 28.9784)
var params = CalculationMethod.turkey.params
params.madhab = .shafi
return PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params)
}
}
struct PrayerTimeView: View {
@Binding var times: PrayerTimes?
let prayers: [Prayer] = [.fajr, .sunrise, .dhuhr, .asr, .maghrib, .isha]
var body: some View {
List {
ForEach(prayers, id: \.self) { prayer in
HStack {
self.formattedPrayerName(prayer: prayer)
self.formattedPrayerTime(prayer: prayer, times: self.times)
}
}
}
.listStyle(InsetGroupedListStyle())
}
func formattedPrayerTime(prayer: Prayer, times: PrayerTimes?) -> some View {
guard let time = times?.time(for: prayer) else {
return Text("-")
}
return Text("\(time, formatter: dateFormatter)").foregroundColor(.red)
}
func formattedPrayerName(prayer: Prayer) -> some View {
switch prayer {
case .fajr:
return Text("Fajr: ")
case .sunrise:
return Text("Sunrise:")
case .dhuhr:
return Text("Dhuhr: ")
case .asr:
return Text("Asr: ")
case .maghrib:
return Text("Maghrib:")
case .isha:
return Text("Isha: ")
}
}
}
struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
AthanView3()
}
}
I believe you have to use the time zone consistently everywhere, so even in calendar:
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "Europe/Istanbul")
@basememara when I try it it gives me this error if I end it with ! nothing happens
what I have noticed is that in some places like Amman or Istanbul for example, the actual prayer time is behind the prayer time shown by Adhan-swift by almost exactly one hour
Here is my code: