Git Product home page Git Product logo

prayer-times's Introduction

CI Releases

Prayer Times Library (PHP)

This is a PHP edition of the Prayer Times Library (v2.3) originally written in JavaScript by Hamid Zarrabi-Zadeh of PrayTimes.org and available on http://praytimes.org/code/v2/js/PrayTimes.js. It has divulged much from the original since it was first written, so please don't use it as a 'like for like' substitute - the method names, among other things, are different.

How to Use this Library

The library is a composer package, so to install it, run:

composer require islamic-network/prayer-times

Using it is rather simple:

<?php
require_once("vendor/autoload.php");
use IslamicNetwork\PrayerTimes\PrayerTimes;

// Instantiate the class with your chosen method, Juristic School for Asr and if you want or own Asr factor, make the juristic school null and pass your own Asr shadow factor as the third parameter. Note that all parameters are optional.

$pt = new PrayerTimes('ISNA'); // new PrayerTimes($method, $asrJuristicMethod, $asrShadowFactor);

// Then, to get times for today.

$times = $pt->getTimesForToday($latitude, $longitude, $timezone, $elevation = null, $latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, $midnightMode = self::MIDNIGHT_MODE_STANDARD, $format = self::TIME_FORMAT_24H);

// Or, if you want times for another day

$times = $pt->getTimes(DateTime $date, $latitude, $longitude, $elevation = null, $latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, $midnightMode = self::MIDNIGHT_MODE_STANDARD, $format = self::TIME_FORMAT_24H);

//If you would like to offset the time for each result by a particular number of minutes, simply call the tune method before calling getTimes or getTimesForToday.

$pt->tune($imsak = 0, $fajr= 0, $sunrise = 0, $dhuhr = 0, $asr = 0, $maghrib = 0, $sunset = 0, $isha = 0, $midnight = 0);

// Finally, you can also create your own methods:
$method = new Method('My Custom Method');
$method->setFajrAngle(18);
$method->setMaghribAngleOrMins(19.5);
$method->setIshaAngleOrMins('90 min');
// And then:
$pt = new PrayerTimes(PrayerTimes::METHOD_CUSTOM);
$pt->setCustomMethod($method);
// And then the same as before:
$times = $pt->getTimesForToday($latitude, $longitude, $timezone, $elevation = null, $latitudeAdjustmentMethod = self::LATITUDE_ADJUSTMENT_METHOD_ANGLE, $midnightMode = self::MIDNIGHT_MODE_STANDARD, $format = self::TIME_FORMAT_24H);

Methods

Supported methods can be seen @ https://github.com/islamic-network/prayer-times/blob/master/src/PrayerTimes/Method.php#L10.

Understanding Methods

For a discussion on methods, see https://aladhan.com/calculation-methods.

Tests

Compare the results produced by this library against the original JS version.

Contributors

Hamid Zarrabi-Zadeh, Meezaan-ud-Din Abdu Dhil-Jalali Wal-Ikram

License

Same as the original - License: GNU LGPL v3.0, which effectively means:

Permission is granted to use this code, with or without modification, in any website or application provided that credit is given to the original work with a link back to PrayTimes.org.

prayer-times's People

Contributors

ameir avatar cpfair avatar draliragab avatar jstaerk avatar meezaan avatar yazanmy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prayer-times's Issues

Asr calculation uses server's system time, drifts over course of day

As-salaamu alaykum,

I noticed that the Asr calculation uses the server's local time for the fractional component of the Julian day (date('i') + date('s')):

private function gregorianToJulianDate(): float
{
$julianDate = gregoriantojd($this->date->format('n'), $this->date->format('d'), $this->date->format('Y'));
//correct for half-day offset
$dayfrac = date('G') / 24 - .5;
if ($dayfrac < 0) $dayfrac += 1;
//now set the fraction of a day
$frac = $dayfrac + (date('i') + date('s') / 60) / 60 / 24;
return ($julianDate + $frac);
}
/**
* @param $factor
* @param $time
* @return mixed
*/
private function asrTime($factor, $time)
{
$julianDate = $this->gregorianToJulianDate();

This means that the server can return different Asr times for the same API call, depending on when in the day the call is made (relative to the system time of the server).

For example, this randomly generated API call for a specific date and lat/lng. When I made the API call a few days ago at 17:33, the Asr time was 13:57. When I make the same call now (at 08:15), the Asr time is 13:59. All other times are identical, as one would hope.

I don't think the Asr time should change based on when the API call is made relative to the server's clock. I think the original PrayTimes calculation is correct here.

Call to undefined function IslamicNetwork\PrayerTimes\gregoriantojd()

I encountered an issue while using your library prayer-times in my Laravel 10 application (current version). When I run the command php artisan serve, it shows the following error:

Error Screenshot

After some investigation, I found that the PHP function gregoriantojd() used in line 533 of the PrayerTimes.php class is not recognized by the current PHP version. My current PHP version is:

PHP Version Screenshot

The library works fine in Homestead, where the PHP version is:

Homestead PHP Version Screenshot

Additional Information:
In addition, I noticed a discrepancy in line 533 of the PrayerTimes.php class . Specifically, it suggests receiving the year using $this->date->format('y'), but according to the PHP documentation, it should be received as $this->date->format('Y') to represent the four-digit year. Please consider updating this part of the code for consistency and compatibility.

Please advise on how to resolve this compatibility issue or if there is a recommended PHP version for using the prayer-times library.

Thank you!

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.