Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply daylight saving time with fixed prayer times #22

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions MuslimData/Classes/Extensions/DateExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ public extension Date {
func addMinutes(_ minutes: Double) -> Date {
addingTimeInterval(60 * minutes)
}

/// Add hours to the date.
///
/// - Parameter hours: hours to be added to the date.
/// - Returns: New date that added the specified hours.
func addHours(_ hours: Double) -> Date {
addingTimeInterval(60 * 60 * hours)
}
}
18 changes: 17 additions & 1 deletion MuslimData/Classes/Prayer Times/PrayerTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ public struct PrayerTime {
maghrib = maghrib.addMinutes(offsets[4])
isha = isha.addMinutes(offsets[5])
}


/// Apply daylight saving time to the current prayer times.
private mutating func applyDST() {

let isDST = TimeZone.current.isDaylightSavingTime()

if (isDST) {
fajr = fajr.addHours(1)
sunrise = sunrise.addHours(1)
dhuhr = dhuhr.addHours(1)
asr = asr.addHours(1)
maghrib = maghrib.addHours(1)
isha = isha.addHours(1)
}
}

// MARK: - Public Methods

/// Get prayer times from the prayer database.
Expand Down Expand Up @@ -94,6 +109,7 @@ public struct PrayerTime {
maghrib: maghrib.toDate(date),
isha: isha.toDate(date))
prayerTime.applyOffsets(attributes.offsets)
prayerTime.applyDST()
callback(prayerTime, nil)
}
}
Expand Down
Loading