Skip to content

Instantly share code, notes, and snippets.

@iamriajul
Created March 29, 2022 03:42
Show Gist options
  • Save iamriajul/2cdbc15d4fd0e8bad203205c9302a54b to your computer and use it in GitHub Desktop.
Save iamriajul/2cdbc15d4fd0e8bad203205c9302a54b to your computer and use it in GitHub Desktop.
getPrayerStatus() returns running & next prayer.
fun getPrayerStatus(timeTable: PrayerTimeTable): PrayerStatus? {
val running = timeTable.times.firstOrNull { it.isRunning }
val next = timeTable.findClosestFutureByStart()
return if (running != null && next != null) {
PrayerStatus(
timeTable.date,
running,
next
)
} else if (running == null && next != null) {
// The Next Prayer is The First Prayer of The Day. Most Probably Tahajjud.
val prayerTimeTableForLastDay = prayerTimeTableService.get(
timeTable.latLng,
timeTable.date.minusDays(1),
timeTable.method,
timeTable.timeAdjustments,
timeTable.madhab,
timeTable.highLatitudeRule
)
val runningPrayerForLastDay =
prayerTimeTableForLastDay.times.firstOrNull { it.isRunning }
if (runningPrayerForLastDay != null) {
PrayerStatus(
timeTable.date,
runningPrayerForLastDay,
next
)
} else {
null
}
} else if (next == null && running != null) {
// The Running Prayer Is Last Prayer of The Day. Most Probably Isha.
val prayerTimeTableForNextDay = prayerTimeTableService.get(
timeTable.latLng,
timeTable.date.plusDays(1),
timeTable.method,
timeTable.timeAdjustments,
timeTable.madhab,
timeTable.highLatitudeRule
)
val firstPrayerForNextDay = prayerTimeTableForNextDay.findClosestFutureByStart()
if (firstPrayerForNextDay != null) {
PrayerStatus(
timeTable.date,
running,
firstPrayerForNextDay
)
} else {
null
}
} else {
null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment