Code Monkey home page Code Monkey logo

Comments (7)

korbav avatar korbav commented on September 24, 2024

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.

farisfaisalthena avatar farisfaisalthena commented on September 24, 2024

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.

farisfaisalthena avatar farisfaisalthena commented on September 24, 2024

Just curious why does this.time.nextPrayer() not return a string? seems like the interface shows its using Date

from adhan-js.

korbav avatar korbav commented on September 24, 2024

Just curious why does this.time.nextPrayer() not return a string? seems like the interface shows its using Date

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.

farisfaisalthena avatar farisfaisalthena commented on September 24, 2024

does it cause you any limitation/trouble?

No actually but just curious why something like asr does not return as string

from adhan-js.

korbav avatar korbav commented on September 24, 2024

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.

github-actions avatar github-actions commented on September 24, 2024

Stale issue message

from adhan-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.