Skip to content

Commit

Permalink
add typescript definitions, better enum raw values, removed use of va…
Browse files Browse the repository at this point in the history
…r whenever possible
  • Loading branch information
z3bi committed Apr 16, 2020
1 parent 752e15f commit 3a696e3
Show file tree
Hide file tree
Showing 21 changed files with 400 additions and 269 deletions.
86 changes: 86 additions & 0 deletions Adhan.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
export as namespace adhan;

export class PrayerTimes {
constructor(coordinates: Coordinates, date: Date, params: CalculationParameters);

fajr: Date;
sunrise: Date;
dhuhr: Date;
asr: Date;
maghrib: Date;
isha: Date;

timeForPrayer(prayer: Prayer): Date;
currentPrayer(date?: Date): Prayer;
nextPrayer(date?: Date): Prayer;
}

export class CalculationParameters {
constructor(fajrAngle: number, ishaAngle: number, ishaInterval: number, methodName?: string)

readonly method: string;
fajrAngle: number;
ishaAngle: number;
ishaInterval: number;
madhab: Madhab;
highLatitudeRule: HighLatitudeRule;
adjustments: PrayerAdjustments;
}

export interface PrayerAdjustments {
fajr: number;
sunrise: number;
dhuhr: number;
asr: number;
maghrib: number;
isha: number;
}

export namespace CalculationMethod {
export function MuslimWorldLeague(): CalculationParameters;
export function Egyptian(): CalculationParameters;
export function Karachi(): CalculationParameters;
export function UmmAlQura(): CalculationParameters;
export function Dubai(): CalculationParameters;
export function MoonsightingCommittee(): CalculationParameters;
export function NorthAmerica(): CalculationParameters;
export function Kuwait(): CalculationParameters;
export function Qatar(): CalculationParameters;
export function Singapore(): CalculationParameters;
export function Other(): CalculationParameters;
}

export class Coordinates {
constructor(longitude: number, latitude: number);
longitude: number;
latitude: number;
}

export class SunnahTimes {
constructor(prayerTimes: PrayerTimes);

middleOfTheNight: Date;
lastThirdOfTheNight: Date;
}

export enum Madhab {
Shafi,
Hanafi
}

export enum Prayer {
Fajr,
Sunrise,
Dhuhr,
Asr,
Maghrib,
Isha,
None
}

export enum HighLatitudeRule {
MiddleOfTheNight,
SeventhOfTheNight,
TwilightAngle
}

74 changes: 43 additions & 31 deletions Adhan.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Adhan.js.map

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
## Upgrading from 1.0.1 to 2.0.0
Upgrading to 2.0.0 introduces breaking API changes.
## Upgrading from 3.0.0 to 4.0.0
Upgrading to 4.0.0 introduces breaking API changes.

JavaScript `Date` and `Number` prototypes are no longer patched by this library.
The library should now be pure without any side effects.
The `adhan.Date.formattedTime` convenience function is no longer provided by this library.
These functions obscure the difficulty in dealing with Daylight Savings Time
and other timezone issues.

This means you can no longer depend on methods like `formattedTime` being directly accessible on the Date instance. For example,
Instead you should use a timezone aware date formatting library like [moment](https://momentjs.com).

**Before**:

```js
prayerTimes.fajr.formattedTime(); // no longer works
adhan.Date.formattedTime(prayerTimes.fajr); // no longer available
```

**After**:

```js
adhan.Date.formattedTime(prayerTimes.fajr); // works
moment(prayerTimes.fajr).tz('America/New_York').format('h:mm A'); // Recommended method
```
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Adhan was designed to work in the browser and in Node.js

### Browser

Simply include Adhan.js in your HTML page

```
<script src="Adhan.js"></script>
<script>
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "adhan",
"version": "3.0.0",
"version": "4.0.0",
"description": "Adhan is a well tested and well documented library for calculating Islamic prayer times. 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.",
"main": "Adhan.js",
"types": "Adhan.d.ts",
"scripts": {
"build": "webpack --mode production",
"test": "jest",
Expand All @@ -20,6 +21,9 @@
],
"author": "Batoul Apps",
"license": "MIT",
"contributors": [
"Ameir Al-Zoubi"
],
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
Expand Down
2 changes: 1 addition & 1 deletion src/Adhan.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Coordinates from './Coordinates';
import PrayerTimes from './PrayerTimes';
import Prayer from './Prayer';
import Madhab from './Madhab';
import { Madhab } from './Madhab';
import HighLatitudeRule from './HighLatitudeRule';
import CalculationMethod from './CalculationMethod';
import CalculationParameters from './CalculationParameters';
Expand Down
14 changes: 7 additions & 7 deletions src/CalculationMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import CalculationParameters from './CalculationParameters';
const CalculationMethod = {
// Muslim World League
MuslimWorldLeague: function() {
var params = new CalculationParameters(18, 17, 0, "MuslimWorldLeague");
let params = new CalculationParameters(18, 17, 0, "MuslimWorldLeague");
params.methodAdjustments = { dhuhr: 1 };
return params;
},

// Egyptian General Authority of Survey
Egyptian: function() {
var params = new CalculationParameters(19.5, 17.5, 0, "Egyptian");
let params = new CalculationParameters(19.5, 17.5, 0, "Egyptian");
params.methodAdjustments = { dhuhr: 1 };
return params;
},

// University of Islamic Sciences, Karachi
Karachi: function() {
var params = new CalculationParameters(18, 18, 0, "Karachi");
let params = new CalculationParameters(18, 18, 0, "Karachi");
params.methodAdjustments = { dhuhr: 1 };
return params;
},
Expand All @@ -29,21 +29,21 @@ const CalculationMethod = {

// Dubai
Dubai: function() {
var params = new CalculationParameters(18.2, 18.2, 0, "Dubai");
let params = new CalculationParameters(18.2, 18.2, 0, "Dubai");
params.methodAdjustments = { sunrise: -3, dhuhr: 3, asr: 3, maghrib: 3 };
return params;
},

// Moonsighting Committee
MoonsightingCommittee: function() {
var params = new CalculationParameters(18, 18, 0, "MoonsightingCommittee");
let params = new CalculationParameters(18, 18, 0, "MoonsightingCommittee");
params.methodAdjustments = { dhuhr: 5, maghrib: 3 };
return params;
},

// ISNA
NorthAmerica: function() {
var params = new CalculationParameters(15, 15, 0, "NorthAmerica");
let params = new CalculationParameters(15, 15, 0, "NorthAmerica");
params.methodAdjustments = { dhuhr: 1 };
return params;
},
Expand All @@ -60,7 +60,7 @@ const CalculationMethod = {

// Singapore
Singapore: function() {
var params = new CalculationParameters(20, 18, 0, "Singapore");
let params = new CalculationParameters(20, 18, 0, "Singapore");
params.methodAdjustments = { dhuhr: 1 };
return params;
},
Expand Down
2 changes: 1 addition & 1 deletion src/CalculationParameters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Madhab from './Madhab';
import { Madhab } from './Madhab';
import HighLatitudeRule from './HighLatitudeRule';

export default class CalculationParameters {
Expand Down
Loading

0 comments on commit 3a696e3

Please sign in to comment.