Skip to content

Commit

Permalink
Merge pull request #22 from kosratdev/dst-feature
Browse files Browse the repository at this point in the history
Apply daylight saving time with fixed prayer times
  • Loading branch information
kosratdev committed Mar 7, 2024
2 parents eade9f1 + 07ec1a0 commit 3c691da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit 3c691da

Please sign in to comment.