batoulapps / adhan-js

High precision Islamic prayer time library for JavaScript
MIT License
376 stars 86 forks source link

Add Correction time #77

Closed farisfaisalthena closed 2 years ago

farisfaisalthena commented 3 years ago

Not sure if this is possible, but it would be great to add a new option to allow dev to correct the minute time. Currently I have to do something like this.time.fajr.setMinutes(this.time.fajr.getMinutes() + 10) for each one of the prayers.

korbav commented 3 years ago

You can make use of the adjustments parameter for that.

let params = adhan.CalculationMethod.MuslimWorldLeague();
params.adjustments = { fajr: 10, sunrise: 10, dhuhr: 10, maghrib: 10, isha: 10 };
farisfaisalthena commented 3 years ago

Dint realise this existed. Thanks

farisfaisalthena commented 3 years ago

Is it possible to update the time in realtime? for example if user changes the adjustments time in settings i will have to restart the app. Can it be done automatically on change?

korbav commented 3 years ago

Is it possible to update the time in real time? for example, if user changes the adjustments time in settings i will have to restart the app. Can it be done automatically on change?

Your app must be able to trigger a recomputation without a restart, and then, accordingly updating the UI, which should not be a problem with any modern framework.

This library is built to give you only one calculation result, which makes sense since even if it would give you "real-time" results you would still have to have a timer to refresh the UI, so make use of this timer not only to update the UI but also to calculate again the prayers times :

Basic example:

let times;
const refreshUI = () => {
  if (null !== times) {
     // Do whatever with times variable
  }
}

setInterval(() => {
     times = new adhan.PrayerTimes(coordinates, date, params);
     refreshUI();
}, 60 * 1000);
atif089 commented 2 years ago

@farisfaisalthena

Here's an interactive demo using ReactJS - https://8n5y0.csb.app/

github-actions[bot] commented 2 years ago

Stale issue message