batoulapps / adhan-js

High precision Islamic prayer time library for JavaScript
MIT License
368 stars 81 forks source link

Understanding the functionality of nextPrayer and currentPrayer #128

Closed Zalanshah64 closed 1 year ago

Zalanshah64 commented 1 year ago

Often, I'll find that the output of the currentPrayer and nextPrayer functions can be "none". I'm unsure of why, and was hoping somebody could explain exactly when the output would be "none" and when it could output something else.

z3bi commented 1 year ago

A PrayerTimes object is only for a single day so a currentPrayer would be none if time for fajr has not yet begun because it does not know about the previous day's Isha. Similarly nextPrayer would be none if the time for isha has started since it doesn't know about tomorrow's fajr.

It is recommended to check for these values of none and compute the previous or next day's prayer times to show the appropriate next or current prayer.

z3bi commented 1 year ago

Also the currentPrayer and nextPrayer functions default to using the current date but you can also pass in a specific date for more advanced checks or for testing purposes.