GithubHelp home page GithubHelp logo

sigmasd / adhan-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from batoulapps/adhan-js

0.0 1.0 0.0 5.35 MB

High precision Islamic prayer time library for JavaScript

License: MIT License

Shell 0.12% JavaScript 2.82% TypeScript 94.74% HTML 2.32%

adhan-js's Introduction

Adhan JavaScript

badge-version badge-travis badge-cov Commitizen friendly semantic-release

Adhan JavaScript is a well tested and well documented library for calculating Islamic prayer times in JavaScript using Node or a web browser.

All astronomical calculations are high precision equations directly from the book “Astronomical Algorithms” by Jean Meeus. This book is recommended by the Astronomical Applications Department of the U.S. Naval Observatory and the Earth System Research Laboratory of the National Oceanic and Atmospheric Administration.

Implementations of Adhan in other languages can be found in the parent repo Adhan.

Installation

Adhan was designed to work in both the browser and NodeJS applications.

Browser

We provide both ESM and UMD bundles for use in the browser.

Download the latest release and check under package/lib/bundles.

<script src="adhan.umd.min.js"></script>
<script>
  var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
</script>

Node

Both CommonJS and ES Module libraries are provided.

npm install adhan

CommonJS:

const adhan = require('adhan');
const prayerTimes = new adhan.PrayerTimes(coordinates, date, params);

ES Modules:

import { Coordinates, CalculationMethod, PrayerTimes } from 'adhan';
const coordinates = new Coordinates(35.7897507, -78.6912485);
const params = CalculationMethod.MoonsightingCommittee();
const date = new Date(2022, 3, 20);
const prayerTimes = new PrayerTimes(coordinates, date, params);

Migration

Migrating from version 3.x? Read the migration guide

Usage

To get prayer times initialize a new PrayerTimes object passing in coordinates, date, and calculation parameters.

const prayerTimes = new PrayerTimes(coordinates, date, params);

Initialization parameters

Coordinates

Create a Coordinates object with the latitude and longitude for the location you want prayer times for.

const coordinates = new Coordinates(35.78056, -78.6389);

Date

The date parameter passed in should be an instance of the JavaScript Date object. The year, month, and day values need to be populated. All other values will be ignored. The year, month and day values should be for the date that you want prayer times for. These date values are expected to be for the Gregorian calendar.

const date = new Date();
const date = new Date(2015, 11, 1);

Calculation parameters

The rest of the needed information is contained within the CalculationParameters object.

Calculation Parameters & Methods Guide

Prayer Times

Once the PrayerTimes object has been initialized it will contain values for all five prayer times and the time for sunrise. The prayer times will be Date object instances initialized with UTC values. You will then need to format the times for the correct timezone. You can do that by using a timezone aware date formatting library like moment.

moment(prayerTimes.fajr).tz('America/New_York').format('h:mm A');

Full Example

import {
  Coordinates,
  CalculationMethod,
  PrayerTimes,
  SunnahTimes,
  Prayer,
  Qibla,
} from 'adhan';
import moment from 'moment-timezone';

const coordinates = new Coordinates(35.7897507, -78.6912485);
const params = CalculationMethod.MoonsightingCommittee();
const date = new Date();
const prayerTimes = new PrayerTimes(coordinates, date, params);
const sunnahTimes = new SunnahTimes(prayerTimes);

Edit Adhan Example

Convenience Utilities

The PrayerTimes object has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it easier to dynamically show countdowns until the next prayer.

var prayerTimes = new PrayerTimes(coordinates, date, params);

var current = prayerTimes.currentPrayer();
var next = prayerTimes.nextPrayer();
var nextPrayerTime = prayerTimes.timeForPrayer(next);

Sunnah Times

The Adhan library can also calulate Sunnah times. Given an instance of PrayerTimes, you can get a SunnahTimes object with the times for Qiyam.

var sunnahTimes = new SunnahTimes(prayerTimes);
var middleOfTheNight = moment(sunnahTimes.middleOfTheNight)
  .tz('America/New_York')
  .format('h:mm A');
var lastThirdOfTheNight = moment(sunnahTimes.lastThirdOfTheNight)
  .tz('America/New_York')
  .format('h:mm A');

Qibla Direction

Get the direction, in degrees from North, of the Qibla from a given set of coordinates.

var coordinates = new Coordinates(35.78056, -78.6389);
var qiblaDirection = Qibla(coordinates);

Contributing

Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all developers. We accept feature contributions provided that they are properly documented and include the appropriate unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different locations, we do ask that the source of the comparison values be properly documented.

Note: Commit messages should follow the commit message convention so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. If you are not familiar with the commit message convention, you should use npm run commit instead of git commit, which provides an interactive CLI for generating proper commit messages.

License

Adhan is available under the MIT license. See the LICENSE file for more info.

adhan-js's People

Contributors

abumalick avatar ahmedre avatar b-stud avatar basememara avatar dependabot[bot] avatar insha avatar jd1378 avatar kafiln avatar khawarizmus avatar meltuhamy avatar mmahalwy avatar mmmoussa avatar mzc13 avatar n-eq avatar semantic-release-bot avatar sgtsquiggs avatar thekbn avatar z3bi avatar zapolnoch avatar

Watchers

 avatar

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.