Comments (7)
You can do it quite simply with the following :
const prayersTimes = new adhan.PrayersTimes(...);
prayersTimes.prayers = [adhan.Prayer.Fajr, adhan.Prayer.Sunrise, adhan.Prayer.Dhuhr, adhan.Prayer.Asr, adhan.Prayer.Maghrib, adhan.Prayer.Isha]
.map((name) => ({ name, time: prayersTimes[name] }))
For your information, we are currently working on a scheduler, I was intending to offer such a current method, so hopefully, it will be part of the implementation.
from adhan-js.
alright then. just to add the implementation below:
const prayers = [adhan.Prayer.Fajr, adhan.Prayer.Sunrise, adhan.Prayer.Dhuhr, adhan.Prayer.Asr, adhan.Prayer.Maghrib, adhan.Prayer.Isha].map((name) => ({ name, time: this.time[name] }))
const final = {
prayers,
nextPrayers: {
name: this.time.nextPrayer(),
time: this.time.timeForPrayer(this.time.nextPrayer())
}
}
This also includes the next prayers information. Besides that you could also add the current prayers in there. Thanks!
from adhan-js.
Just curious why does this.time.nextPrayer()
not return a string? seems like the interface shows its using Date
from adhan-js.
Just curious why does
this.time.nextPrayer()
not return a string? seems like the interface shows its usingDate
Because a date object is probably the most pertinent and expectable type to return when it comes to prayers times, does it cause you any limitation/trouble?
You can easily format it to a string at your convenience with JS built-in functions, or using more advanced libs like Intl, or even using external libraries like moment or luxon (which might sound overkilled though)
from adhan-js.
does it cause you any limitation/trouble?
No actually but just curious why something like asr
does not return as string
from adhan-js.
does it cause you any limitation/trouble?
No actually but just curious why something like
asr
does not return as string
I got you, you're right, the objects returned by timeToNextPrayer are not dates, they are of type Prayer
:
nextPrayer(date?: Date): Prayer
The Prayer type is actually an enumeration of strings in Typescript :
const Prayer = {
Fajr: 'fajr',
Sunrise: 'sunrise',
Dhuhr: 'dhuhr',
Asr: 'asr',
Maghrib: 'maghrib',
Isha: 'isha',
None: 'none'
}
It's a pretty common thing to use this kind of object to identify values in a cleaner way than doing string comparisons. For example, if tomorrow we want to change the string values to capital values (ie. asr
becomes ASR
),
The following instruction will still work if(prayer === adhan.Prayer.Asr)
But this one will break if(prayer === 'asr')
I advise you to use adhan.Prayer.XXX
in your code instead of string values, here is a little example if you need https://codesandbox.io/s/trusting-forest-o7n17?file=/src/index.js
from adhan-js.
Stale issue message
from adhan-js.
Related Issues (20)
- Prayer Ending Times HOT 1
- Understanding the functionality of nextPrayer and currentPrayer HOT 2
- Moon Phases?
- Wrong time returned HOT 1
- [suggestion]: Use `const enums` for some constant variables
- time difference for asr on Turkey HOT 1
- The use of Temporal HOT 2
- [suggestion]: Add 'Imsak' Timings HOT 4
- Host the javascript on cdnjs or similar HOT 1
- Turkish Diyanet times for Netherlands gives wrong for yatsi time
- Reason for using sth like moment.js HOT 2
- Taking elevation into account for prayer times HOT 1
- Considering elevation for Salah times HOT 21
- TypeError: Cannot read properties of undefined (reading 'getTime') HOT 1
- add adjustment settings to sunset HOT 6
- Prayer times are wrong(?) HOT 16
- The possibility of adjusting the midnight time HOT 1
- Calculation is returning prayer times for next day instead of "today" HOT 3
- Getting Default Calculation Method for Location
- Wrong times HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adhan-js.