Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export sunsetTime in prayerTimes #105

Closed
jd1378 opened this issue May 5, 2022 · 7 comments
Closed

Export sunsetTime in prayerTimes #105

jd1378 opened this issue May 5, 2022 · 7 comments
Labels

Comments

@jd1378
Copy link
Contributor

jd1378 commented May 5, 2022

Hi
It would be good if the sunset time was also exported from prayerTimes and in the nextPrayer method

because in some calculation Maqrib prayer time is not same as sunset

@z3bi
Copy link
Contributor

z3bi commented May 5, 2022

@jd1378 is your use case that you want to be able to display both Maghrib and sunset?

@jd1378
Copy link
Contributor Author

jd1378 commented May 5, 2022

yes

@z3bi
Copy link
Contributor

z3bi commented May 5, 2022

I don't think it makes sense to add it to nextPrayer since sunset isn't a prayer. Maghrib is the prayer time. We include sunrise since thats when the prayer time for Fajr specifically ends. It might make more sense to export SolarTime instead if you just want times of the sunset itself.

@jd1378
Copy link
Contributor Author

jd1378 commented May 5, 2022

well its same usecase for maqrib in some places, it ends the prayer time for asr

@jd1378
Copy link
Contributor Author

jd1378 commented May 5, 2022

But exporting SolarTime would be nice as well, but that would need exporting PolarCircleResolution ,TimeComponents and DateUtils to do the same thing as the lib is doing

@jd1378
Copy link
Contributor Author

jd1378 commented May 5, 2022

I've already written a helper for myself, but I thought it would be nicer if the lib did it in the first place:

import {Coordinates, PolarCircleResolution} from 'adhan';

// @ts-ignore
import {isValidDate} from 'adhan/src/DateUtils';
// @ts-ignore
import {polarCircleResolvedValues} from 'adhan/src/PolarCircleResolution';
// @ts-ignore
import SolarTime from 'adhan/src/SolarTime';
// @ts-ignore
import TimeComponents from 'adhan/src/TimeComponents';

export function getSunset(
  date: Date,
  coordinates: Coordinates,
  polarCircleResolver = PolarCircleResolution.Unresolved,
): Date {
  let solarTime = new SolarTime(date, coordinates);
  let sunsetTime = new TimeComponents(solarTime.sunset).utcDate(
    date.getFullYear(),
    date.getMonth(),
    date.getDate(),
  );
  if (
    !isValidDate(sunsetTime) &&
    polarCircleResolver !== PolarCircleResolution.Unresolved
  ) {
    const resolved = polarCircleResolvedValues(
      polarCircleResolver,
      date,
      coordinates,
    );
    solarTime = resolved.solarTime;
    const dateComponents = [
      date.getFullYear(),
      date.getMonth(),
      date.getDate(),
    ];
    sunsetTime = new TimeComponents(solarTime.sunset).utcDate(
      ...dateComponents,
    );
  }

  return sunsetTime;
}

@z3bi z3bi closed this as completed in 05a0c34 May 11, 2022
github-actions bot pushed a commit that referenced this issue May 11, 2022
# [4.4.0](v4.3.2...v4.4.0) (2022-05-11)

### Features

* **prayertimes:** expose sunset time ([05a0c34](05a0c34)), closes [#105](#105)
@github-actions
Copy link

🎉 This issue has been resolved in version 4.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants