Skip to content

Commit

Permalink
feat(calculation params): adds shafaq parameter
Browse files Browse the repository at this point in the history
Adds a new property to calculation parameters shafaq
that is used by the MoonsightingCommittee method to
calculate Isha.
  • Loading branch information
z3bi committed Dec 30, 2021
1 parent 2e24417 commit 131515f
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Adhan.xcodeproj/project.pbxproj
Expand Up @@ -82,6 +82,10 @@
84B2C70F256CB1E70097C96C /* Rouding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B2C70C256CB1E70097C96C /* Rouding.swift */; };
84B2C710256CB1E70097C96C /* Rouding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B2C70C256CB1E70097C96C /* Rouding.swift */; };
84BCD1B01CB09A7700614D12 /* TimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BCD1AF1CB09A7700614D12 /* TimeTests.swift */; };
84D70F702778231400B3027D /* Shafaq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D70F6F2778231400B3027D /* Shafaq.swift */; };
84D70F712778231400B3027D /* Shafaq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D70F6F2778231400B3027D /* Shafaq.swift */; };
84D70F722778231400B3027D /* Shafaq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D70F6F2778231400B3027D /* Shafaq.swift */; };
84D70F732778231400B3027D /* Shafaq.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D70F6F2778231400B3027D /* Shafaq.swift */; };
84DC7628214B1B3C003F79FD /* Minute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DC7627214B1B3C003F79FD /* Minute.swift */; };
84F8E1231C7AB542004C48D7 /* Adhan.h in Headers */ = {isa = PBXBuildFile; fileRef = 84F8E1221C7AB542004C48D7 /* Adhan.h */; settings = {ATTRIBUTES = (Public, ); }; };
84F8E12A1C7AB542004C48D7 /* Adhan.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84F8E11F1C7AB542004C48D7 /* Adhan.framework */; };
Expand Down Expand Up @@ -163,6 +167,7 @@
84896CB82558A386008CA6BC /* METHODS.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = METHODS.md; sourceTree = "<group>"; };
84B2C70C256CB1E70097C96C /* Rouding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rouding.swift; sourceTree = "<group>"; };
84BCD1AF1CB09A7700614D12 /* TimeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeTests.swift; sourceTree = "<group>"; };
84D70F6F2778231400B3027D /* Shafaq.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shafaq.swift; sourceTree = "<group>"; };
84DC7627214B1B3C003F79FD /* Minute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Minute.swift; sourceTree = "<group>"; };
84F8E11F1C7AB542004C48D7 /* Adhan.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Adhan.framework; sourceTree = BUILT_PRODUCTS_DIR; };
84F8E1221C7AB542004C48D7 /* Adhan.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Adhan.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -249,6 +254,7 @@
083EFC53202815EE003F6218 /* Prayer.swift */,
088088652026EDF90059C738 /* PrayerAdjustment.swift */,
84B2C70C256CB1E70097C96C /* Rouding.swift */,
84D70F6F2778231400B3027D /* Shafaq.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -636,6 +642,7 @@
0880888F2026EF910059C738 /* Astronomical.swift in Sources */,
088088662026EDF90059C738 /* PrayerAdjustment.swift in Sources */,
0880886B2026EE420059C738 /* CalculationParameters.swift in Sources */,
84D70F702778231400B3027D /* Shafaq.swift in Sources */,
083EFC61202815EE003F6218 /* Prayer.swift in Sources */,
84B2C70D256CB1E70097C96C /* Rouding.swift in Sources */,
083EFC55202815EE003F6218 /* CalculationMethod.swift in Sources */,
Expand Down Expand Up @@ -676,6 +683,7 @@
088088902026EF910059C738 /* Astronomical.swift in Sources */,
088088672026EDF90059C738 /* PrayerAdjustment.swift in Sources */,
0880886C2026EE420059C738 /* CalculationParameters.swift in Sources */,
84D70F712778231400B3027D /* Shafaq.swift in Sources */,
083EFC62202815EE003F6218 /* Prayer.swift in Sources */,
84B2C70E256CB1E70097C96C /* Rouding.swift in Sources */,
083EFC56202815EE003F6218 /* CalculationMethod.swift in Sources */,
Expand All @@ -702,6 +710,7 @@
088088912026EF910059C738 /* Astronomical.swift in Sources */,
088088682026EDF90059C738 /* PrayerAdjustment.swift in Sources */,
0880886D2026EE420059C738 /* CalculationParameters.swift in Sources */,
84D70F722778231400B3027D /* Shafaq.swift in Sources */,
083EFC63202815EE003F6218 /* Prayer.swift in Sources */,
84B2C70F256CB1E70097C96C /* Rouding.swift in Sources */,
083EFC57202815EE003F6218 /* CalculationMethod.swift in Sources */,
Expand All @@ -728,6 +737,7 @@
088088922026EF910059C738 /* Astronomical.swift in Sources */,
088088692026EDF90059C738 /* PrayerAdjustment.swift in Sources */,
0880886E2026EE420059C738 /* CalculationParameters.swift in Sources */,
84D70F732778231400B3027D /* Shafaq.swift in Sources */,
083EFC64202815EE003F6218 /* Prayer.swift in Sources */,
84B2C710256CB1E70097C96C /* Rouding.swift in Sources */,
083EFC58202815EE003F6218 /* CalculationMethod.swift in Sources */,
Expand Down
11 changes: 11 additions & 0 deletions METHODS.md
Expand Up @@ -24,6 +24,7 @@ params.adjustments.fajr = 2
| highLatitudeRule | Which setting from the HighLatitudeRule enum to use for calculating the minimum time for Fajr and the maximum time for Isha. |
| adjustments | PrayerAdjustments struct with custom prayer time adjustments in minutes for each prayer time. |
| rounding | The behavior for rounding prayer times. Either to nearest minute, to the higher minute, or none. |
| shafaq | Used by the MoonsightingCommittee method to determine how to calculate Isha. See explanation of values below. |

## CalculationMethod

Expand Down Expand Up @@ -70,3 +71,13 @@ You can get the recommended High Latitude Rule for a location by calling the `re
let myCoordinates = Coordinates(latitude: 48.983226, longitude: -3.216649)
let highLatRule = HighLatitudeRule.recommended(for: myCoordinates)
```

#### Shafaq

Shafaq is used by the MoonsightingCommittee method to determine what type of twilight to use in order to determine the time for Isha.

| Value | Description |
| ----- | ----------- |
| general | General is a combination of Ahmer and Abyad. This is the defualt value and will provide more reasonable times for locations at higher latitudes. |
| ahmer | Ahmer means the twilight is the red glow in the sky. Used by the Shafi, Maliki, and Hanbali madhabs. This generally produces an earlier Isha time. |
| abyad | Abyad means the twilight is the white glow in the sky. Used by the Hanafi madhab. This generally produces a later Isha time. |
41 changes: 41 additions & 0 deletions Sources/AdhanObjc.swift
Expand Up @@ -132,6 +132,8 @@ import Foundation
open var madhab: BAMadhab = .shafi
open var highLatitudeRule: BAHighLatitudeRule = .middleOfTheNight
open var adjustments: BAPrayerAdjustments = BAPrayerAdjustments()
open var shafaq: BAShafaq = .general
open var rounding: BARounding = .nearest
private var methodAdjustments: BAPrayerAdjustments = BAPrayerAdjustments()

public init(fajrAngle: Double, maghribAngle: Double, ishaAngle: Double, ishaInterval: Int) {
Expand All @@ -147,6 +149,15 @@ import Foundation
self.init(fajrAngle: params.fajrAngle, maghribAngle: params.maghribAngle ?? 0, ishaAngle: params.ishaAngle, ishaInterval: params.ishaInterval)
self.method = method
self.methodAdjustments = BAPrayerAdjustments(fajr: params.methodAdjustments.fajr, sunrise: params.methodAdjustments.sunrise, dhuhr: params.methodAdjustments.dhuhr, asr: params.methodAdjustments.asr, maghrib: params.methodAdjustments.maghrib, isha: params.methodAdjustments.isha)

switch params.rounding {
case .nearest:
self.rounding = .nearest
case .up:
self.rounding = .up
case .none:
self.rounding = .none
}
}

internal func calculationParameters() -> CalculationParameters {
Expand All @@ -173,6 +184,24 @@ import Foundation
params.highLatitudeRule = HighLatitudeRule.twilightAngle
}

switch self.shafaq {
case BAShafaq.general:
params.shafaq = Shafaq.general
case BAShafaq.ahmer:
params.shafaq = Shafaq.ahmer
case BAShafaq.abyad:
params.shafaq = Shafaq.abyad
}

switch self.rounding {
case BARounding.nearest:
params.rounding = Rounding.nearest
case BARounding.up:
params.rounding = Rounding.up
case BARounding.none:
params.rounding = Rounding.none
}

return params
}

Expand Down Expand Up @@ -229,6 +258,18 @@ import Foundation
case hanafi
}

@objc public enum BAShafaq: Int {
case general
case ahmer
case abyad
}

@objc public enum BARounding: Int {
case nearest
case up
case none
}

@objc public enum BAHighLatitudeRule: Int {
case middleOfTheNight
case seventhOfTheNight
Expand Down
27 changes: 21 additions & 6 deletions Sources/Astronomy/Astronomical.swift
Expand Up @@ -279,12 +279,27 @@ struct Astronomical {
}

/* Twilight adjustment based on observational data for use in the Moonsighting Committee calculation method. */
static func seasonAdjustedEveningTwilight(latitude: Double, day: Int, year: Int, sunset: Date) -> Date {
let a: Double = 75 + ((25.60 / 55.0) * fabs(latitude))
let b: Double = 75 + ((2.050 / 55.0) * fabs(latitude))
let c: Double = 75 - ((9.210 / 55.0) * fabs(latitude))
let d: Double = 75 + ((6.140 / 55.0) * fabs(latitude))

static func seasonAdjustedEveningTwilight(latitude: Double, day: Int, year: Int, sunset: Date, shafaq: Shafaq) -> Date {
let a, b, c, d: Double

switch shafaq {
case .general:
a = 75 + ((25.60 / 55.0) * fabs(latitude))
b = 75 + ((2.050 / 55.0) * fabs(latitude))
c = 75 - ((9.210 / 55.0) * fabs(latitude))
d = 75 + ((6.140 / 55.0) * fabs(latitude))
case .ahmer:
a = 62 + ((17.40 / 55.0) * fabs(latitude))
b = 62 - ((7.160 / 55.0) * fabs(latitude))
c = 62 + ((5.120 / 55.0) * fabs(latitude))
d = 62 + ((19.44 / 55.0) * fabs(latitude))
case .abyad:
a = 75 + ((25.60 / 55.0) * fabs(latitude))
b = 75 + ((7.160 / 55.0) * fabs(latitude))
c = 75 + ((36.84 / 55.0) * fabs(latitude))
d = 75 + ((81.84 / 55.0) * fabs(latitude))
}

let adjustment: Double = {
let dyy = Double(Astronomical.daysSinceSolstice(dayOfYear: day, year: year, latitude: latitude))
if ( dyy < 91) {
Expand Down
1 change: 1 addition & 0 deletions Sources/Models/CalculationParameters.swift
Expand Up @@ -38,6 +38,7 @@ public struct CalculationParameters: Codable, Equatable {
public var highLatitudeRule: HighLatitudeRule? = nil
public var adjustments: PrayerAdjustments = PrayerAdjustments()
public var rounding: Rounding = .nearest
public var shafaq: Shafaq = .general
var methodAdjustments: PrayerAdjustments = PrayerAdjustments()

init(fajrAngle: Double, ishaAngle: Double) {
Expand Down
19 changes: 18 additions & 1 deletion Sources/Models/Rouding.swift
Expand Up @@ -2,9 +2,26 @@
// Rouding.swift
// Adhan
//
// Created by Ameir Al-Zoubi on 11/23/20.
// Copyright © 2020 Batoul Apps. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation

Expand Down
51 changes: 51 additions & 0 deletions Sources/Models/Shafaq.swift
@@ -0,0 +1,51 @@
//
// Shafaq.swift
// Adhan
//
// Copyright © 2021 Batoul Apps. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation

/**
Shafaq is the twilight in the sky. Different madhabs define the appearance of
twilight differently. These values are used by the MoonsightingComittee method
for the different ways to calculate Isha.
*Values*
**general**
General is a combination of Ahmer and Abyad.
**ahmer**
Ahmer means the twilight is the red glow in the sky. Used by the Shafi, Maliki, and Hanbali madhabs.
**abyad**
Abyad means the twilight is the white glow in the sky. Used by the Hanafi madhab.
*/
public enum Shafaq: String, Codable, CaseIterable {
case general
case ahmer
case abyad
}
2 changes: 1 addition & 1 deletion Sources/PrayerTimes.swift
Expand Up @@ -127,7 +127,7 @@ public struct PrayerTimes {

let safeIsha: Date = {
guard calculationParameters.method != .moonsightingCommittee else {
return Astronomical.seasonAdjustedEveningTwilight(latitude: coordinates.latitude, day: dayOfYear, year: year, sunset: sunsetDate)
return Astronomical.seasonAdjustedEveningTwilight(latitude: coordinates.latitude, day: dayOfYear, year: year, sunset: sunsetDate, shafaq: calculationParameters.shafaq)
}

let portion = calculationParameters.nightPortions(using: coordinates).isha
Expand Down

0 comments on commit 131515f

Please sign in to comment.