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

Add new calculation methods #59

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 194 additions & 32 deletions Swift/Adhan/Adhan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,64 +113,226 @@ public struct CalculationParameters {
}

/* Preset calculation parameters */
public enum CalculationMethod {
public enum CalculationMethod: Int {

/// Returns array of all the calculation methods available
public static var all: [CalculationMethod] {
return [CalculationMethod.algerian, .diyanet, .egyptianGeneralAuthority, .egyptianGeneralNewAuthority, .france15, .france18, .franceUOIF, .JAKIM, .jordan, .karachi, .kementerian, .kuwait, .MUIS, .moonsightingCommittee, .muslimWorldLeague, .northAmerica, .oman, .qatar, .russia, .tunisian, .UAE, .ummAlQura, .ummAlQuraRamadan].sorted {
$0.0.title < $0.1.title
}
}

// Muslim World League
case muslimWorldLeague
/// Algerian Ministry of Religious Affairs
/// Fajr: 18,0 / Isha: 17,0
case algerian

//Egyptian General Authority of Survey
case egyptian
/// Diyanet İşleri Başkanlığı, Türkiye
/// Fajr: 18,0 / Isha: 17,0
case diyanet

// University of Islamic Sciences, Karachi
case karachi
/// Egyptian General Authority of Survey
/// Fajr: 19,5 / Isha: 17,5
case egyptianGeneralAuthority

// Umm al-Qura University, Makkah
case ummAlQura
/// Egyptian General Authority of Survey
/// Fajr: 20,0 / Isha: 18,0
case egyptianGeneralNewAuthority

/// France - Angle 15
/// Fajr: 15,0 / Isha: 15,0
case france15

// The Gulf Region
/// France - Angle 18
/// Fajr: 18,0 / Isha: 18,0
case france18

/// Union des Organisations Islamiques de France
/// Fajr: 12,0 / Isha: 12,0
case franceUOIF

/// The Gulf Region
case gulf

// Moonsighting Committee
/// Jabatan Kemajuan Islam Malaysia - JAKIM
/// Fajr: 20,0 / Isha: 18,0
case JAKIM

/// Jordan, Ministry of Awqaf and Islamic Affairs
/// Fajr: 18,0 / Isha: 18,0
case jordan

/// University of Islamic Sciences, Karachi
/// Fajr: 18,0 / Isha: 18,0
case karachi

/// Kementerian Agama Republik Indonesia
/// Fajr: 20,0 / Isha: 18,0
case kementerian

/// Kuwait, Ministry of Awqaf and Islamic Affairs
/// Fajr: 18,0 / Isha: 17,5
case kuwait

/// Moonsighting Committee
case moonsightingCommittee

// ISNA
/// Majlis Ugama Islam Singapura - MUIS
/// Fajr: 20,0 / Isha: 18,0
case MUIS

/// Muslim World League
/// Fajr: 18,0 / Isha: 17,0
case muslimWorldLeague

/// ISNA
/// Fajr: 15,0 / Isha angle: 15,0
case northAmerica

// Kuwait
case kuwait
/// Oman, Ministry of Awqaf and Islamic Affairs
/// Fajr: 18,0 / Isha: 90 min. after Maghrib
case oman

// Qatar
/// Qatar, Ministry of Awqaf and Islamic Affairs
/// Fajr: 18,0 / Isha: 90 min. after Maghrib
case qatar

// Other
/// Russia
/// Fajr: 16,0 / Isha: 15,0
case russia

/// Tunisian Ministry of Religious Affairs
/// Fajr: 18,0 / Isha: 18,0
case tunisian

/// UAE General Authority of Islamic Affairs and Endowments
/// Fajr: 19,5 / Isha: 90 min. after Maghrib
case UAE

/// Umm al-Qura University, Makkah
/// Fajr: 18,0 / Isha: 90 min. after Maghrib
case ummAlQura

/// Umm al-Qura University, Makkah
/// Fajr: 18,0 / Isha: 120 min. after Maghrib
case ummAlQuraRamadan

case other


/// Title of CalculationMethod
public var title: String {
switch self {
case .algerian: return "Algerian Minister of Religioous Affairs and Awqaf"
case .diyanet: return "Diyanet İşleri Başkanlığı, Türkiye"
case .egyptianGeneralAuthority: return "Egyptian General Authority of Survey"
case .egyptianGeneralNewAuthority: return "Egyptian General New Authority of Survey"
case .france15: return "France - Angle 15"
case .france18: return "France - Angle 18"
case .franceUOIF: return "France UOIF - Angle 12"
case .JAKIM: return "Jabatan Kemajuan Islam Malaysia - JAKIM"
case .jordan: return "Jordan, Ministry of Awqaf and Islamic Affairs"
case .kementerian: return "Kementerian Agama Republik Indonesia"
case .kuwait: return "Kuwait, Ministry of Awqaf and Islamic Affairs"
case .MUIS: return "Majlis Ugama Islam Singapura - MUIS"
case .muslimWorldLeague: return "Muslim World League - MWL"
case .northAmerica: return "North America - ISNA"
case .oman: return "Oman, Ministry of Awqaf and Islamic Affairs"
case .qatar: return "Qatar, Ministry of Awqaf and Islamic Affairs"
case .russia: return "Russia"
case .tunisian: return "Tunisian Ministry of Religious Affairs"
case .UAE: return "UAE General Authority of Islamic Affairs and Endowments"
case .ummAlQura: return "Umm al-Qura University"
case .ummAlQuraRamadan: return "Umm Al-Qura University (Ramadan)"
case .karachi: return "University of Islamic Sciences, Karachi"
case .moonsightingCommittee: return "Moonsighting Committee Worldwide"
case .gulf: return "Gulf"
case .other: return "Other"
}
}

public var params: CalculationParameters {
switch(self) {
case .muslimWorldLeague:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17, method: self)
case .egyptian:
return CalculationParameters(fajrAngle: 19.5, ishaAngle: 17.5, method: self)
case .karachi:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)
case .ummAlQura:
return CalculationParameters(fajrAngle: 18.5, ishaInterval: 90, method: self)
switch self {

case .algerian:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17, method: self)

case .diyanet:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17, method: self)

case .egyptianGeneralAuthority:
return CalculationParameters(fajrAngle: 19.5, ishaAngle: 17.5, method: self)

case .egyptianGeneralNewAuthority:
return CalculationParameters(fajrAngle: 20, ishaAngle: 18, method: self)

case .france15:
return CalculationParameters(fajrAngle: 15, ishaAngle: 15, method: self)

case .france18:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)

case .franceUOIF:
return CalculationParameters(fajrAngle: 12, ishaAngle: 12, method: self)

case .gulf:
return CalculationParameters(fajrAngle: 19.5, ishaInterval: 90, method: self)
return CalculationParameters(fajrAngle: 19.5, ishaInterval: 90, method: self)

case .JAKIM:
return CalculationParameters(fajrAngle: 20, ishaAngle: 18, method: self)

case .jordan:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)

case .karachi:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)

case .kementerian:
return CalculationParameters(fajrAngle: 20, ishaAngle: 18, method: self)

case .kuwait:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17.5, method: self)

case .moonsightingCommittee:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)

case .MUIS:
return CalculationParameters(fajrAngle: 20, ishaAngle: 18, method: self)

case .muslimWorldLeague:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17, method: self)

case .northAmerica:
return CalculationParameters(fajrAngle: 15, ishaAngle: 15, method: self)
case .kuwait:
return CalculationParameters(fajrAngle: 18, ishaAngle: 17.5, method: self)
return CalculationParameters(fajrAngle: 15, ishaAngle: 15, method: self)

case .oman:
return CalculationParameters(fajrAngle: 18, ishaInterval: 90, method: self)

case .qatar:
return CalculationParameters(fajrAngle: 18, ishaInterval: 90, method: self)
return CalculationParameters(fajrAngle: 18, ishaInterval: 90, method: self)

case .russia:
return CalculationParameters(fajrAngle: 16, ishaAngle: 15, method: self)

case .tunisian:
return CalculationParameters(fajrAngle: 18, ishaAngle: 18, method: self)

case .UAE:
return CalculationParameters(fajrAngle: 18.5, ishaInterval: 90, method: self)

case .ummAlQura:
return CalculationParameters(fajrAngle: 18.5, ishaInterval: 90, method: self)

case .ummAlQuraRamadan:
return CalculationParameters(fajrAngle: 18.5, ishaInterval: 120, method: self)

case .other:
return CalculationParameters(fajrAngle: 0, ishaAngle: 0, method: self)
return CalculationParameters(fajrAngle: 0, ishaAngle: 0, method: self)

}
}
}


/* Prayer times for a location and date using the given calculation parameters.
All prayer times are in UTC and should be display using a DateFormatter that
has the correct timezone set. */
Expand Down
70 changes: 45 additions & 25 deletions Swift/Adhan/AdhanObjc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,40 +151,60 @@ import Foundation

private static func calculationMethodForBACalculationMethod(_ baMethod: BACalculationMethod) -> CalculationMethod {
switch baMethod {
case .muslimWorldLeague:
return CalculationMethod.muslimWorldLeague
case .egyptian:
return CalculationMethod.egyptian
case .karachi:
return CalculationMethod.karachi
case .ummAlQura:
return CalculationMethod.ummAlQura
case .gulf:
return CalculationMethod.gulf
case .moonsightingCommittee:
return CalculationMethod.moonsightingCommittee
case .northAmerica:
return CalculationMethod.northAmerica
case .kuwait:
return CalculationMethod.kuwait
case .qatar:
return CalculationMethod.qatar
case .other:
return CalculationMethod.other
case .algerian: return CalculationMethod.algerian
case .diyanet: return CalculationMethod.diyanet
case .egyptianGeneralAuthority: return CalculationMethod.egyptianGeneralAuthority
case .egyptianGeneralNewAuthority: return CalculationMethod.egyptianGeneralNewAuthority
case .france15: return CalculationMethod.france15
case .france18: return CalculationMethod.france18
case .franceUOIF: return CalculationMethod.franceUOIF
case .gulf: return CalculationMethod.gulf
case .JAKIM: return CalculationMethod.JAKIM
case .jordan: return CalculationMethod.jordan
case .karachi: return CalculationMethod.karachi
case .kementerian: return CalculationMethod.kementerian
case .kuwait: return CalculationMethod.kuwait
case .moonsightingCommittee: return CalculationMethod.moonsightingCommittee
case .MUIS: return CalculationMethod.MUIS
case .muslimWorldLeague: return CalculationMethod.muslimWorldLeague
case .northAmerica: return CalculationMethod.northAmerica
case .oman: return CalculationMethod.oman
case .qatar: return CalculationMethod.qatar
case .russia: return CalculationMethod.russia
case .tunisian: return CalculationMethod.tunisian
case .UAE: return CalculationMethod.UAE
case .ummAlQura: return CalculationMethod.ummAlQura
case .ummAlQuraRamadan: return CalculationMethod.ummAlQuraRamadan
case .other: return CalculationMethod.other
}
}
}

@objc public enum BACalculationMethod: Int {
case muslimWorldLeague
case egyptian
case karachi
case ummAlQura
case algerian
case diyanet
case egyptianGeneralAuthority
case egyptianGeneralNewAuthority
case france15
case france18
case franceUOIF
case gulf
case JAKIM
case jordan
case karachi
case kementerian
case kuwait
case moonsightingCommittee
case MUIS
case muslimWorldLeague
case northAmerica
case kuwait
case oman
case qatar
case russia
case tunisian
case UAE
case ummAlQura
case ummAlQuraRamadan
case other
}

Expand Down
4 changes: 2 additions & 2 deletions Swift/AdhanTests/AdhanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class AdhanTests: XCTestCase {
XCTAssertEqual(p1.ishaInterval, 0)
XCTAssertEqual(p1.method, CalculationMethod.muslimWorldLeague)

let p2 = CalculationMethod.egyptian.params
let p2 = CalculationMethod.egyptianGeneralAuthority.params
XCTAssertEqual(p2.fajrAngle, 19.5)
XCTAssertEqual(p2.ishaAngle, 17.5)
XCTAssertEqual(p2.ishaInterval, 0)
XCTAssertEqual(p2.method, CalculationMethod.egyptian)
XCTAssertEqual(p2.method, CalculationMethod.egyptianGeneralAuthority)

let p3 = CalculationMethod.karachi.params
XCTAssertEqual(p3.fajrAngle, 18)
Expand Down
2 changes: 1 addition & 1 deletion Swift/AdhanTests/ObjcTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (BACalculationParameters *)parseParams:(NSDictionary *)dict {
if ([method isEqualToString:@"MuslimWorldLeague"]) {
params = [[BACalculationParameters alloc] initWithMethod:BACalculationMethodMuslimWorldLeague];
} else if ([method isEqualToString:@"Egyptian"]) {
params = [[BACalculationParameters alloc] initWithMethod:BACalculationMethodEgyptian];
params = [[BACalculationParameters alloc] initWithMethod:BACalculationMethodEgyptianGeneralAuthority];
} else if ([method isEqualToString:@"Karachi"]) {
params = [[BACalculationParameters alloc] initWithMethod:BACalculationMethodKarachi];
} else if ([method isEqualToString:@"UmmAlQura"]) {
Expand Down
2 changes: 1 addition & 1 deletion Swift/AdhanTests/TimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TimeTests: XCTestCase {
if method == "MuslimWorldLeague" {
params = CalculationMethod.muslimWorldLeague.params
} else if method == "Egyptian" {
params = CalculationMethod.egyptian.params
params = CalculationMethod.egyptianGeneralAuthority.params
} else if method == "Karachi" {
params = CalculationMethod.karachi.params
} else if method == "UmmAlQura" {
Expand Down