├── .travis.yml ├── Tests ├── en.lproj │ └── InfoPlist.strings ├── Tests-Prefix.pch ├── Tests-Info.plist └── Tests.m ├── OCPrayerTimes ├── OCPrayerTimes-Prefix.pch ├── main.m ├── OCPrayerTimes.1 ├── PrayTime.h └── PrayTime.m ├── .gitignore ├── OCPrayerTimes.podspec ├── LICENSE ├── AppleDoc.md ├── README.md └── OCPrayerTimes.xcodeproj └── project.pbxproj /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c -------------------------------------------------------------------------------- /Tests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Tests/Tests-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #import 10 | #endif 11 | -------------------------------------------------------------------------------- /OCPrayerTimes/OCPrayerTimes-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import 9 | #import 10 | #endif 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *~.nib 4 | 5 | build/ 6 | 7 | *.pbxuser 8 | *.perspective 9 | *.perspectivev3 10 | 11 | *.mode1v3 12 | *.mode2v3 13 | 14 | # Xcode 5 15 | *.xcuserstate 16 | *.xccheckout 17 | project.xcworkspace/ 18 | xcuserdata/ 19 | 20 | # CocoaPods 21 | Pods/ 22 | Podfile.lock 23 | -------------------------------------------------------------------------------- /Tests/Tests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | my.com.smd.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /OCPrayerTimes.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'OCPrayerTimes' 3 | s.version = '0.1.0' 4 | s.license = 'MIT' 5 | s.summary = 'Objective-C library for Muslim Prayer Times' 6 | s.homepage = 'https://www.github.com/sumardi/OCPrayerTimes' 7 | s.author = { 'Sumardi Shukor' => 'me@sumardi.net' } 8 | s.source = { :git => 'https://github.com/sumardi/OCPrayerTimes.git', :tag => '0.1.0' } 9 | s.ios.deployment_target = '6.0' 10 | s.ios.frameworks = 'Foundation', 'CoreLocation' 11 | s.ios.source_files = 'OCPrayerTimes/*.{h,m}' 12 | s.osx.deployment_target = '10.8' 13 | s.osx.frameworks = 'Foundation', 'CoreLocation' 14 | s.osx.source_files = 'OCPrayerTimes/*.{h,m}' 15 | s.requires_arc = true 16 | s.prefix_header_file = 'OCPrayerTimes/OCPrayerTimes-Prefix.pch' 17 | end -------------------------------------------------------------------------------- /Tests/Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // Tests.m 3 | // Tests 4 | // 5 | // Created by Sumardi Shukor on 10/13/13. 6 | // Copyright (c) 2013 Software Machine Development. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "PrayTime.h" 11 | 12 | @interface Tests : XCTestCase { 13 | PrayTime *prayTime; 14 | } 15 | 16 | @end 17 | 18 | @implementation Tests 19 | 20 | // The setUp method is called automatically for each test-case method 21 | // (methods whose name starts with 'test'). 22 | - (void)setUp 23 | { 24 | [super setUp]; 25 | 26 | prayTime = [[PrayTime alloc] init]; 27 | } 28 | 29 | // This method is called after the invocation of each test method in the class. 30 | - (void)tearDown 31 | { 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testInstance 36 | { 37 | XCTAssertNotNil(prayTime, @"Cannot find PrayTime instance"); 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 OCDiscount (https://www.github.com/sumardi/OCPrayerTimes) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /OCPrayerTimes/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // OCPrayerTimes 4 | // 5 | // Created by Sumardi Shukor on 10/13/13. 6 | // Copyright (c) 2013 Software Machine Development. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "PrayTime.h" 11 | 12 | int main(int argc, const char * argv[]) 13 | { 14 | 15 | @autoreleasepool { 16 | PrayTime *prayerTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 17 | andCalculation:CalculationMethodMWL]; 18 | [prayerTime setTimeFormat:TimeFormat12Hour]; 19 | 20 | // Example 1 21 | NSDateComponents *comps = [[NSDateComponents alloc] init]; 22 | [comps setDay:13]; 23 | [comps setMonth:10]; 24 | [comps setYear:2013]; 25 | NSMutableArray *times1 = [prayerTime getPrayerTimesForDate:comps 26 | withLatitude:3.1667 27 | longitude:101.7000 28 | andTimeZone:[prayerTime getTimeZone]]; 29 | NSLog(@"%@", times1); 30 | 31 | // Example 2 32 | NSMutableArray *times2 = [prayerTime prayerTimesDate:[NSDate date] 33 | latitude:3.1667 34 | longitude:101.7000 35 | andTimezone:[prayerTime getTimeZone]]; 36 | 37 | NSLog(@"%@", times2); 38 | } 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /OCPrayerTimes/OCPrayerTimes.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 10/13/13 \" DATE 7 | .Dt OCPrayerTimes 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm OCPrayerTimes, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /AppleDoc.md: -------------------------------------------------------------------------------- 1 | # Objective-C Library for Muslim Prayer Times 2 | 3 | [![Build Status](https://travis-ci.org/sumardi/OCPrayerTimes.png)](https://travis-ci.org/sumardi/OCPrayerTimes) 4 | 5 | OCPrayerTimes is an Objective-C library for calculating Muslim Prayer Times. 6 | Modified version of the original source code written by Hamid Zarrabi-Zadeh and 7 | Hussain Ali from [PrayTimes.org][1]. The source code was modified by [Sumardi Shukor][2] 8 | for taking advantage of modern Objective-C language such as [ARC][3], [object literals][4], etc. 9 | 10 | [1]: http://www.praytimes.org 11 | [2]: https://www.twitter.com/sumardi 12 | [3]: http://clang.llvm.org/docs/AutomaticReferenceCounting.html 13 | [4]: http://clang.llvm.org/docs/ObjectiveCLiterals.html 14 | 15 | ## Requirements 16 | 17 | OCPrayerTimes 0.1.0 and higher requires Xcode 5, targeting either iOS 6.0 and above, 18 | or Mac OS 10.8 Mountain Lion (64-bit with modern Cocoa runtime) and above. 19 | 20 | The following Cocoa frameworks must be linked into the application target for proper compilation: 21 | 22 | * **CoreLocation.framework** 23 | 24 | ## Installation 25 | 26 | ### CocoaPods (Recommended) 27 | 28 | [CocoaPods][5] is the recommended way to add OCPrayerTimes to your Xcode project. 29 | 30 | Here's an example `Podfile` that installs OCPrayerTimes. 31 | 32 | [5]: http://www.cocoapods.org 33 | 34 | #### Podfile 35 | 36 | platform :osx, '10.8' 37 | pod 'OCPrayerTimes', '~> 0.1.0' 38 | 39 | Then run `pod install`. 40 | 41 | ### Manual 42 | 43 | Just add `PrayTime.h` and `PrayTime.m` to your Xcode project. 44 | 45 | ## Examples 46 | 47 | Depending on how you configure your project you may need to `#import` either `` or `"PrayTime.h"`. 48 | 49 | ### Getting prayer times for a given longitude and latitude 50 | 51 | 52 | PrayTime *prayerTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 53 | andCalculation:CalculationMethodMWL]; 54 | NSMutableArray *prayerTimes = [prayerTime prayerTimesDate:[NSDate date] 55 | latitude:3.1667 56 | longitude:101.7000 57 | andTimezone:[prayerTime getTimeZone]]; 58 | NSLog(@"%@", prayerTimes); 59 | 60 | 61 | 62 | ### Getting prayer times from current user location 63 | 64 | 65 | - (void)viewDidLoad 66 | { 67 | [super viewDidLoad]; 68 | 69 | self.locationManager = [[CLLocationManager alloc] init]; 70 | self.locationManager.distanceFilter = kCLDistanceFilterNone; 71 | self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 72 | self.locationManager.delegate = self; 73 | 74 | [self.locationManager startUpdatingLocation]; 75 | 76 | prayTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 77 | andCalculation:CalculationMethodMWL]; 78 | [prayTime setTimeFormat:TimeFormat12Hour]; 79 | } 80 | 81 | - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 82 | { 83 | CLLocation *location = [locations lastObject]; 84 | 85 | praytime = [prayTime prayerTimesFromLocation:location 86 | forDate:[NSDate date]]; 87 | } 88 | 89 | 90 | ## License 91 | 92 | OCPrayerTimes is available under the MIT license (see LICENSE file). 93 | 94 | PrayTimes is free software; it is released under a GNU LGPL v3.0 license 95 | that allows you to do as you wish with it as long as you don't attempt 96 | to claim it as your own work. 97 | 98 | ## Reference 99 | 100 | - [http://www.praytimes.org](http://www.praytimes.org) 101 | 102 | ## Support 103 | 104 | Bugs and feature request are tracked on [Github](https://github.com/sumardi/OCPrayerTimes/issues) 105 | 106 | ## Credit 107 | 108 | The code on which this package is [based][1], is principally developed and maintained by [Sumardi Shukor][2]. 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Objective-C Library for Muslim Prayer Times 2 | 3 | [![Build Status](https://travis-ci.org/sumardi/OCPrayerTimes.png)](https://travis-ci.org/sumardi/OCPrayerTimes) 4 | 5 | OCPrayerTimes is an Objective-C library for calculating Muslim Prayer Times. 6 | Modified version of the original source code written by Hamid Zarrabi-Zadeh and 7 | Hussain Ali from [PrayTimes.org][1]. The source code was modified by [Sumardi Shukor][2] 8 | for taking advantage of modern Objective-C language such as [ARC][3], [object literals][4], etc. 9 | 10 | [1]: http://www.praytimes.org 11 | [2]: https://www.twitter.com/sumardi 12 | [3]: http://clang.llvm.org/docs/AutomaticReferenceCounting.html 13 | [4]: http://clang.llvm.org/docs/ObjectiveCLiterals.html 14 | 15 | ## Requirements 16 | 17 | OCPrayerTimes 0.1.0 and higher requires Xcode 5, targeting either iOS 6.0 and above, 18 | or Mac OS 10.8 Mountain Lion (64-bit with modern Cocoa runtime) and above. 19 | 20 | The following Cocoa frameworks must be linked into the application target for proper compilation: 21 | 22 | * **CoreLocation.framework** 23 | 24 | ## Installation 25 | 26 | ### CocoaPods (Recommended) 27 | 28 | [CocoaPods][5] is the recommended way to add OCPrayerTimes to your Xcode project. 29 | 30 | Here's an example `Podfile` that installs OCPrayerTimes. 31 | 32 | [5]: http://www.cocoapods.org 33 | 34 | #### Podfile 35 | 36 | ```ruby 37 | platform :osx, '10.8' 38 | pod 'OCPrayerTimes', '~> 0.1.0' 39 | ``` 40 | 41 | Then run `pod install`. 42 | 43 | ### Manual 44 | 45 | Just add `PrayTime.h` and `PrayTime.m` to your Xcode project. 46 | 47 | ## Examples 48 | 49 | Depending on how you configure your project you may need to `#import` either `` or `"PrayTime.h"`. 50 | 51 | ### Getting prayer times for a given longitude and latitude 52 | 53 | ```objective-c 54 | PrayTime *prayerTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 55 | andCalculation:CalculationMethodMWL]; 56 | NSMutableArray *prayerTimes = [prayerTime prayerTimesDate:[NSDate date] 57 | latitude:3.1667 58 | longitude:101.7000 59 | andTimezone:[prayerTime getTimeZone]]; 60 | NSLog(@"%@", prayerTimes); 61 | 62 | ``` 63 | 64 | ### Getting prayer times from current user location 65 | 66 | ```objective-c 67 | - (void)viewDidLoad 68 | { 69 | [super viewDidLoad]; 70 | 71 | self.locationManager = [[CLLocationManager alloc] init]; 72 | self.locationManager.distanceFilter = kCLDistanceFilterNone; 73 | self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 74 | self.locationManager.delegate = self; 75 | 76 | [self.locationManager startUpdatingLocation]; 77 | 78 | prayTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 79 | andCalculation:CalculationMethodMWL]; 80 | [prayTime setTimeFormat:TimeFormat12Hour]; 81 | } 82 | 83 | - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 84 | { 85 | CLLocation *location = [locations lastObject]; 86 | 87 | praytime = [prayTime prayerTimesFromLocation:location 88 | forDate:[NSDate date]]; 89 | } 90 | ``` 91 | 92 | ## Documentation 93 | 94 | - [OCPrayerTimes Reference](http://sumardi.github.io/OCPrayerTimes) 95 | - [PrayTime Class Reference](http://sumardi.github.io/OCPrayerTimes/Classes/PrayTime.html) 96 | 97 | ## License 98 | 99 | OCPrayerTimes is available under the MIT license (see LICENSE file). 100 | 101 | PrayTimes is free software; it is released under a GNU LGPL v3.0 license 102 | that allows you to do as you wish with it as long as you don't attempt 103 | to claim it as your own work. 104 | 105 | ## Reference 106 | 107 | - [http://www.praytimes.org](http://www.praytimes.org) 108 | - [Prayer Times Calculation](http://www.praytimes.org/wiki/Prayer_Times_Calculation) 109 | 110 | ## Support 111 | 112 | Bugs and feature request are tracked on [Github](https://github.com/sumardi/OCPrayerTimes/issues) 113 | 114 | ## Credit 115 | 116 | The code on which this package is [based][1], is principally developed and maintained by [Sumardi Shukor][2]. 117 | -------------------------------------------------------------------------------- /OCPrayerTimes/PrayTime.h: -------------------------------------------------------------------------------- 1 | // 2 | // PrayTime.h 3 | // OCPrayerTimes 4 | // 5 | // Created by Sumardi Shukor on 10/13/13. 6 | // Copyright (c) 2013 Software Machine Development. All rights reserved. 7 | // 8 | // Modified version of the original source code written by Hussain Ali. 9 | // Converted to the Modern Objective-C Syntax. 10 | // 11 | // Objective C Code By: Hussain Ali Khan 12 | // Original JS Code By: Hamid Zarrabi-Zadeh 13 | // Original Source from : PrayTimes.org 14 | // 15 | // OCPrayerTimes podspec created and maintained by: 16 | // Sumardi Shukor 17 | // https://www.github.com/sumardi/OCPrayerTimes 18 | // 19 | 20 | #import 21 | #import 22 | 23 | /** 24 | * These constants are used to specify the prayer times calculation method. 25 | * 26 | * @since Available in 0.1.0 and later. 27 | **/ 28 | typedef NS_ENUM(NSInteger, CalculationMethod) { 29 | /** Ithna Ashari. 30 | * @since Available in 0.1.0 and later. 31 | */ 32 | CalculationMethodJafari = 0, 33 | /** University of Islamic Sciences, Karachi. 34 | * @since Available in 0.1.0 and later. 35 | */ 36 | CalculationMethodKarachi = 1, 37 | /** Islamic Society of North America (ISNA). 38 | * @since Available in 0.1.0 and later. 39 | */ 40 | CalculationMethodISNA = 2, 41 | /** Muslim World League (MWL). 42 | * @since Available in 0.1.0 and later. 43 | */ 44 | CalculationMethodMWL = 3, 45 | /** Umm al-Qura, Makkah. 46 | * @since Available in 0.1.0 and later. 47 | */ 48 | CalculationMethodMakkah = 4, 49 | /** Egyptian General Authority of Survey. 50 | * @since Available in 0.1.0 and later. 51 | */ 52 | CalculationMethodEgypt = 5, 53 | /** Institute of Geophysics, University of Tehran. 54 | * @since Available in 0.1.0 and later. 55 | */ 56 | CalculationMethodTehran = 6, 57 | /** Custom Setting. 58 | * @since Available in 0.1.0 and later. 59 | */ 60 | CalculationMethodCustom = 7 61 | }; 62 | 63 | /** 64 | * These constants are used to specify the juristic method. 65 | * 66 | * @since Available in 0.1.0 and later. 67 | */ 68 | typedef NS_ENUM(NSInteger, JuristicMethod) { 69 | /** 70 | * The standard method (which is used by Imamas Shafii, Hanbali, and Maliki) the Asr prayer time starts when the shadow of an object is equivalent to its height. 71 | * 72 | * @since Available in 0.1.0 and later. 73 | */ 74 | JuristicMethodShafii = 0, 75 | /** 76 | * The Hanafi method the Asr prayer time starts when the shadow of an object is twice its height. 77 | * 78 | * @since Available in 0.1.0 and later. 79 | */ 80 | JuristicMethodHanafi = 1 // 81 | }; 82 | 83 | /** 84 | * These constants are used to specify the adjusting methods for higher latitudes. 85 | * 86 | * @since Available in 0.1.0 and later. 87 | */ 88 | typedef NS_ENUM(NSInteger, AdjustMethodHigherLatitude) { 89 | /** 90 | * No adjustment. 91 | * 92 | * @since Available in 0.1.0 and later. 93 | */ 94 | AdjustMethodHigherLatitudeNone = 0, 95 | /** 96 | * Middle of night. 97 | * 98 | * @since Available in 0.1.0 and later. 99 | */ 100 | AdjustMethodHigherLatitudeMidNight = 1, 101 | /** 102 | * 1/7th of night. 103 | * 104 | * @since Available in 0.1.0 and later. 105 | */ 106 | AdjustMethodHigherLatitudeOneSevent = 2, 107 | /** 108 | * Angle/60th of night. 109 | * 110 | * @since Available in 0.1.0 and later. 111 | */ 112 | AdjustMethodHigherLatitudeAngleBased = 3 113 | }; 114 | 115 | /** 116 | * These constants are used to specify the time format. 117 | * 118 | * @since Available in 0.1.0 and later. 119 | */ 120 | typedef NS_ENUM(NSInteger, TimeFormat) { 121 | /** 122 | * Specifies time in the standard 24-hour format. 123 | * 124 | * @since Available in 0.1.0 and later. 125 | */ 126 | TimeFormat24Hour = 0, 127 | /** 128 | * Specifies time in the standard 12-hour format. 129 | * 130 | * @since Available in 0.1.0 and later. 131 | */ 132 | TimeFormat12Hour = 1, 133 | /** 134 | * Specifies time in the standard 12-hour format without suffix. 135 | * 136 | * @since Available in 0.1.0 and later. 137 | */ 138 | TimeFormat12WithNoSuffix = 2, 139 | /** 140 | * Specifies time in floating point number. 141 | * 142 | * @since Available in 0.1.0 and later. 143 | */ 144 | TimeFormatFloat = 3 145 | }; 146 | 147 | 148 | /** 149 | The class for calculating Muslim Prayer Times. 150 | 151 | Depending on how you configure your project you may need to import "PrayTime.h". 152 | 153 | Here is an example for getting prayer times for a given longitude and latitude: 154 | 155 | PrayTime *prayerTime = [[PrayTime alloc] initWithJuristic:JuristicMethodShafii 156 | andCalculation:CalculationMethodMWL]; 157 | NSMutableArray *prayerTimes = [prayerTime prayerTimesDate:[NSDate date] 158 | latitude:3.1667 159 | longitude:101.7000 160 | andTimezone:[prayerTime getTimeZone]]; 161 | */ 162 | @interface PrayTime : NSObject { 163 | 164 | NSMutableArray *timeNames; 165 | NSString *InvalidTime; // The string used for invalid times 166 | 167 | 168 | //--------------------- Technical Settings -------------------- 169 | 170 | NSInteger numIterations; // number of iterations needed to compute times 171 | 172 | //------------------- Calc Method Parameters -------------------- 173 | 174 | NSMutableDictionary *methodParams; 175 | 176 | /* 177 | fa : fajr angle 178 | ms : maghrib selector (0 = angle; 1 = minutes after sunset) 179 | mv : maghrib parameter value (in angle or minutes) 180 | is : isha selector (0 = angle; 1 = minutes after maghrib) 181 | iv : isha parameter value (in angle or minutes) 182 | */ 183 | NSMutableArray *prayerTimesCurrent; 184 | NSMutableArray *offsets; 185 | } 186 | 187 | #pragma mark - Custom Initializers 188 | 189 | /** 190 | * Initializes prayer times instance with the provided values. 191 | * 192 | * @since Available in 0.1.0 and later. 193 | * @param juristic Juristic method for prayer times in `JuristicMethod`. 194 | * @param calculation Prayer calculation method in `CalculationMethod`. 195 | * @returns Returns the instance of `PrayTime`. 196 | */ 197 | - (id)initWithJuristic:(JuristicMethod)juristic andCalculation:(CalculationMethod)calculation; 198 | 199 | #pragma mark - Timezone Methods 200 | 201 | /** 202 | * Returns hours difference in GMT. 203 | * 204 | * @since Available in 0.1.0 and later. 205 | */ 206 | - (double)getTimeZone; 207 | 208 | #pragma mark - Interface Methods 209 | 210 | /** 211 | * Returns prayer times for the provided values. 212 | * 213 | * @since Available in 0.1.0 and later. 214 | * @param year Year. 215 | * @param month Month. 216 | * @param day Day. 217 | * @param latitude The north-south position of a point on the Earth's surface. 218 | * @param longitude Angle which ranges from 0° at the Equator to 90° (North or South) at the poles. 219 | * @param tZone Hours difference in GMT. 220 | * @returns Returns a `NSMutableArray` object of prayer times. 221 | */ 222 | - (NSMutableArray *)getDatePrayerTimesForYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day latitude:(double)latitude longitude:(double)longitude andtimeZone:(double)tZone; 223 | 224 | /** 225 | * Returns prayer times for the provided values. 226 | * 227 | * @since Available in 0.1.0 and later. 228 | * @param date Components of a date. 229 | * @param latitude The north-south position of a point on the Earth's surface. 230 | * @param longitude Angle which ranges from 0° at the Equator to 90° (North or South) at the poles. 231 | * @param tZone Hours difference in GMT. 232 | * @returns Returns a `NSMutableArray` object of prayer times. 233 | */ 234 | - (NSMutableArray *)getPrayerTimesForDate:(NSDateComponents *)date withLatitude:(double)latitude longitude:(double)longitude andTimeZone:(double)tZone; 235 | 236 | /** 237 | * Returns prayer times for the provided values. 238 | * 239 | * @since Available in 0.1.0 and later. 240 | * @param date Date object. 241 | * @param latitude The north-south position of a point on the Earth's surface. 242 | * @param longitude Angle which ranges from 0° at the Equator to 90° (North or South) at the poles. 243 | * @param tZone Hours difference in GMT. 244 | * @returns Returns a `NSMutableArray` object of prayer times. 245 | */ 246 | - (NSMutableArray *)prayerTimesDate:(NSDate *)date latitude:(double)latitude longitude:(double)longitude andTimezone:(double)timezone; 247 | 248 | /** 249 | * Returns prayer times for the provided location. 250 | * 251 | * @since Available in 0.1.0 and later. 252 | * @param location Location object. 253 | * @returns Returns a `NSMutableArray` object of prayer times. 254 | */ 255 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location; 256 | 257 | /** 258 | * Returns prayer times for the provided location and date. 259 | * 260 | * @since Available in 0.1.0 and later. 261 | * @param location `CLLocation` object. 262 | * @param date `NSDate` object. 263 | * @returns Returns a `NSMutableArray` object of prayer times. 264 | */ 265 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location forDate:(NSDate *)date; 266 | 267 | /** 268 | * Returns prayer times for the provided location, date and timezone. 269 | * 270 | * @since Available in 0.1.0 and later. 271 | * @param location Location object. 272 | * @param date Date object. 273 | * @param timezone Timezone object. 274 | * @returns Returns a `NSMutableArray` object of prayer times. 275 | */ 276 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location forDate:(NSDate *)date timezone:(NSTimeZone *)timezone; 277 | 278 | /** 279 | * Sets prayer calculation method. 280 | * 281 | * @since Available in 0.1.0 and later. 282 | * @param method Prayer calculation method in `CalculationMethod`. 283 | * @returns Returns a `NSMutableArray` object of prayer times. 284 | */ 285 | - (void)setCalculationMethod:(CalculationMethod)method; 286 | 287 | /** 288 | * Sets the juristic method for Asr. 289 | * 290 | * @since Available in 0.1.0 and later. 291 | * @param method Prayer calculation method in `JuristicMethod`. 292 | */ 293 | - (void)setJuristicMethod:(JuristicMethod)method; 294 | 295 | /** 296 | * Sets custom values for calculation parameters. 297 | * 298 | * @since Available in 0.1.0 and later. 299 | * @param params Parameters in `NSMutableArray`. 300 | */ 301 | - (void)setCustomParams:(NSMutableArray *)params; 302 | 303 | /** 304 | * Sets the angle for calculating Fajr. 305 | * 306 | * @since Available in 0.1.0 and later. 307 | * @param angle Angle. 308 | */ 309 | - (void)setFajrAngle:(double)angle; 310 | 311 | /** 312 | * Sets the angle for calculating Maghrib. 313 | * 314 | * @since Available in 0.1.0 and later. 315 | * @param angle Angle. 316 | */ 317 | - (void)setMaghribAngle:(double)angle; 318 | 319 | /** 320 | * Sets the angle for calculating Isha. 321 | * 322 | * @since Available in 0.1.0 and later. 323 | * @param angle Angle. 324 | */ 325 | - (void)setIshaAngle:(double)angle; 326 | 327 | /** 328 | * Sets the minutes after mid-day for calculating Dhuhr. 329 | * 330 | * @since Available in 0.1.0 and later. 331 | * @param minutes Minutes after dhuhr. 332 | */ 333 | - (void)setDhuhrMinutes:(double)minutes; 334 | 335 | /** 336 | * Sets the minutes after Sunset for calculating Maghrib. 337 | * 338 | * @since Available in 0.1.0 and later. 339 | * @param minutes Minutes after maghrib. 340 | */ 341 | - (void)setMaghribMinutes:(double)minutes; 342 | 343 | /** 344 | * Sets the minutes after Maghrib for calculating Isha. 345 | * 346 | * @since Available in 0.1.0 and later. 347 | * @param minutes Minutes after isha. 348 | */ 349 | - (void)setIshaMinutes:(double)minutes; 350 | 351 | /** 352 | * Sets adjusting method for higher latitudes. 353 | * 354 | * @since Available in 0.1.0 and later. 355 | * @param method Adjusting method for higher latitude in `AdjustMethodHigherLatitude`. 356 | */ 357 | - (void)setHighLatitudsMethod:(AdjustMethodHigherLatitude)method; 358 | 359 | /** 360 | * Sets time format. 361 | * 362 | * @since Available in 0.1.0 and later. 363 | * @param format Time format in `TimeFormat`. 364 | */ 365 | - (void)setTimeFormat:(TimeFormat)format; 366 | 367 | @end 368 | -------------------------------------------------------------------------------- /OCPrayerTimes.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9F39E6A91809D02C008FDAAA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F39E6A81809D02C008FDAAA /* Foundation.framework */; }; 11 | 9F39E6AC1809D02C008FDAAA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F39E6AB1809D02C008FDAAA /* main.m */; }; 12 | 9F39E6B01809D02C008FDAAA /* OCPrayerTimes.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9F39E6AF1809D02C008FDAAA /* OCPrayerTimes.1 */; }; 13 | 9F39E6B81809D055008FDAAA /* PrayTime.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F39E6B71809D055008FDAAA /* PrayTime.m */; }; 14 | 9F39E6BA180A19BF008FDAAA /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F39E6B9180A19BF008FDAAA /* CoreLocation.framework */; }; 15 | 9F39E702180A9DD0008FDAAA /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F39E701180A9DD0008FDAAA /* XCTest.framework */; }; 16 | 9F39E708180A9DD0008FDAAA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9F39E706180A9DD0008FDAAA /* InfoPlist.strings */; }; 17 | 9F39E70A180A9DD0008FDAAA /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F39E709180A9DD0008FDAAA /* Tests.m */; }; 18 | 9F39E711180A9DE0008FDAAA /* PrayTime.m in Sources */ = {isa = PBXBuildFile; fileRef = 9F39E6B71809D055008FDAAA /* PrayTime.m */; }; 19 | 9F39E712180A9DE8008FDAAA /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F39E6B9180A19BF008FDAAA /* CoreLocation.framework */; }; 20 | 9F39E713180A9DED008FDAAA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F39E6A81809D02C008FDAAA /* Foundation.framework */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 9F39E70C180A9DD0008FDAAA /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 9F39E69D1809D02C008FDAAA /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 9F39E6A41809D02C008FDAAA; 29 | remoteInfo = OCPrayerTimes; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXCopyFilesBuildPhase section */ 34 | 9F39E6A31809D02C008FDAAA /* CopyFiles */ = { 35 | isa = PBXCopyFilesBuildPhase; 36 | buildActionMask = 2147483647; 37 | dstPath = /usr/share/man/man1/; 38 | dstSubfolderSpec = 0; 39 | files = ( 40 | 9F39E6B01809D02C008FDAAA /* OCPrayerTimes.1 in CopyFiles */, 41 | ); 42 | runOnlyForDeploymentPostprocessing = 1; 43 | }; 44 | /* End PBXCopyFilesBuildPhase section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | 9F1677AA180BDE6800EE9DDB /* AppleDoc.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AppleDoc.md; sourceTree = ""; }; 48 | 9F39E6A51809D02C008FDAAA /* OCPrayerTimes */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OCPrayerTimes; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 9F39E6A81809D02C008FDAAA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 50 | 9F39E6AB1809D02C008FDAAA /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 51 | 9F39E6AE1809D02C008FDAAA /* OCPrayerTimes-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OCPrayerTimes-Prefix.pch"; sourceTree = ""; }; 52 | 9F39E6AF1809D02C008FDAAA /* OCPrayerTimes.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = OCPrayerTimes.1; sourceTree = ""; }; 53 | 9F39E6B61809D055008FDAAA /* PrayTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrayTime.h; sourceTree = ""; }; 54 | 9F39E6B71809D055008FDAAA /* PrayTime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrayTime.m; sourceTree = ""; }; 55 | 9F39E6B9180A19BF008FDAAA /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 56 | 9F39E700180A9DD0008FDAAA /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 57 | 9F39E701180A9DD0008FDAAA /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 58 | 9F39E705180A9DD0008FDAAA /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; 59 | 9F39E707180A9DD0008FDAAA /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 60 | 9F39E709180A9DD0008FDAAA /* Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; 61 | 9F39E70B180A9DD0008FDAAA /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 62 | /* End PBXFileReference section */ 63 | 64 | /* Begin PBXFrameworksBuildPhase section */ 65 | 9F39E6A21809D02C008FDAAA /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | 9F39E6BA180A19BF008FDAAA /* CoreLocation.framework in Frameworks */, 70 | 9F39E6A91809D02C008FDAAA /* Foundation.framework in Frameworks */, 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | 9F39E6FD180A9DD0008FDAAA /* Frameworks */ = { 75 | isa = PBXFrameworksBuildPhase; 76 | buildActionMask = 2147483647; 77 | files = ( 78 | 9F39E713180A9DED008FDAAA /* Foundation.framework in Frameworks */, 79 | 9F39E712180A9DE8008FDAAA /* CoreLocation.framework in Frameworks */, 80 | 9F39E702180A9DD0008FDAAA /* XCTest.framework in Frameworks */, 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | 9F39E69C1809D02C008FDAAA = { 88 | isa = PBXGroup; 89 | children = ( 90 | 9F1677AA180BDE6800EE9DDB /* AppleDoc.md */, 91 | 9F39E6AA1809D02C008FDAAA /* OCPrayerTimes */, 92 | 9F39E703180A9DD0008FDAAA /* Tests */, 93 | 9F39E6A71809D02C008FDAAA /* Frameworks */, 94 | 9F39E6A61809D02C008FDAAA /* Products */, 95 | ); 96 | sourceTree = ""; 97 | }; 98 | 9F39E6A61809D02C008FDAAA /* Products */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 9F39E6A51809D02C008FDAAA /* OCPrayerTimes */, 102 | 9F39E700180A9DD0008FDAAA /* Tests.xctest */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | 9F39E6A71809D02C008FDAAA /* Frameworks */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 9F39E6B9180A19BF008FDAAA /* CoreLocation.framework */, 111 | 9F39E6A81809D02C008FDAAA /* Foundation.framework */, 112 | 9F39E701180A9DD0008FDAAA /* XCTest.framework */, 113 | ); 114 | name = Frameworks; 115 | sourceTree = ""; 116 | }; 117 | 9F39E6AA1809D02C008FDAAA /* OCPrayerTimes */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 9F39E6B61809D055008FDAAA /* PrayTime.h */, 121 | 9F39E6B71809D055008FDAAA /* PrayTime.m */, 122 | 9F39E6AB1809D02C008FDAAA /* main.m */, 123 | 9F39E6AF1809D02C008FDAAA /* OCPrayerTimes.1 */, 124 | 9F39E6AD1809D02C008FDAAA /* Supporting Files */, 125 | ); 126 | path = OCPrayerTimes; 127 | sourceTree = ""; 128 | }; 129 | 9F39E6AD1809D02C008FDAAA /* Supporting Files */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 9F39E6AE1809D02C008FDAAA /* OCPrayerTimes-Prefix.pch */, 133 | ); 134 | name = "Supporting Files"; 135 | sourceTree = ""; 136 | }; 137 | 9F39E703180A9DD0008FDAAA /* Tests */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | 9F39E709180A9DD0008FDAAA /* Tests.m */, 141 | 9F39E704180A9DD0008FDAAA /* Supporting Files */, 142 | ); 143 | path = Tests; 144 | sourceTree = ""; 145 | }; 146 | 9F39E704180A9DD0008FDAAA /* Supporting Files */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | 9F39E705180A9DD0008FDAAA /* Tests-Info.plist */, 150 | 9F39E706180A9DD0008FDAAA /* InfoPlist.strings */, 151 | 9F39E70B180A9DD0008FDAAA /* Tests-Prefix.pch */, 152 | ); 153 | name = "Supporting Files"; 154 | sourceTree = ""; 155 | }; 156 | /* End PBXGroup section */ 157 | 158 | /* Begin PBXNativeTarget section */ 159 | 9F39E6A41809D02C008FDAAA /* OCPrayerTimes */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = 9F39E6B31809D02C008FDAAA /* Build configuration list for PBXNativeTarget "OCPrayerTimes" */; 162 | buildPhases = ( 163 | 9F39E6A11809D02C008FDAAA /* Sources */, 164 | 9F39E6A21809D02C008FDAAA /* Frameworks */, 165 | 9F39E6A31809D02C008FDAAA /* CopyFiles */, 166 | ); 167 | buildRules = ( 168 | ); 169 | dependencies = ( 170 | ); 171 | name = OCPrayerTimes; 172 | productName = OCPrayerTimes; 173 | productReference = 9F39E6A51809D02C008FDAAA /* OCPrayerTimes */; 174 | productType = "com.apple.product-type.tool"; 175 | }; 176 | 9F39E6FF180A9DD0008FDAAA /* Tests */ = { 177 | isa = PBXNativeTarget; 178 | buildConfigurationList = 9F39E70E180A9DD0008FDAAA /* Build configuration list for PBXNativeTarget "Tests" */; 179 | buildPhases = ( 180 | 9F39E6FC180A9DD0008FDAAA /* Sources */, 181 | 9F39E6FD180A9DD0008FDAAA /* Frameworks */, 182 | 9F39E6FE180A9DD0008FDAAA /* Resources */, 183 | ); 184 | buildRules = ( 185 | ); 186 | dependencies = ( 187 | 9F39E70D180A9DD0008FDAAA /* PBXTargetDependency */, 188 | ); 189 | name = Tests; 190 | productName = Tests; 191 | productReference = 9F39E700180A9DD0008FDAAA /* Tests.xctest */; 192 | productType = "com.apple.product-type.bundle.unit-test"; 193 | }; 194 | /* End PBXNativeTarget section */ 195 | 196 | /* Begin PBXProject section */ 197 | 9F39E69D1809D02C008FDAAA /* Project object */ = { 198 | isa = PBXProject; 199 | attributes = { 200 | LastUpgradeCheck = 0500; 201 | ORGANIZATIONNAME = "Software Machine Development"; 202 | TargetAttributes = { 203 | 9F39E6FF180A9DD0008FDAAA = { 204 | TestTargetID = 9F39E6A41809D02C008FDAAA; 205 | }; 206 | }; 207 | }; 208 | buildConfigurationList = 9F39E6A01809D02C008FDAAA /* Build configuration list for PBXProject "OCPrayerTimes" */; 209 | compatibilityVersion = "Xcode 3.2"; 210 | developmentRegion = English; 211 | hasScannedForEncodings = 0; 212 | knownRegions = ( 213 | en, 214 | ); 215 | mainGroup = 9F39E69C1809D02C008FDAAA; 216 | productRefGroup = 9F39E6A61809D02C008FDAAA /* Products */; 217 | projectDirPath = ""; 218 | projectRoot = ""; 219 | targets = ( 220 | 9F39E6A41809D02C008FDAAA /* OCPrayerTimes */, 221 | 9F39E6FF180A9DD0008FDAAA /* Tests */, 222 | ); 223 | }; 224 | /* End PBXProject section */ 225 | 226 | /* Begin PBXResourcesBuildPhase section */ 227 | 9F39E6FE180A9DD0008FDAAA /* Resources */ = { 228 | isa = PBXResourcesBuildPhase; 229 | buildActionMask = 2147483647; 230 | files = ( 231 | 9F39E708180A9DD0008FDAAA /* InfoPlist.strings in Resources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXResourcesBuildPhase section */ 236 | 237 | /* Begin PBXSourcesBuildPhase section */ 238 | 9F39E6A11809D02C008FDAAA /* Sources */ = { 239 | isa = PBXSourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | 9F39E6B81809D055008FDAAA /* PrayTime.m in Sources */, 243 | 9F39E6AC1809D02C008FDAAA /* main.m in Sources */, 244 | ); 245 | runOnlyForDeploymentPostprocessing = 0; 246 | }; 247 | 9F39E6FC180A9DD0008FDAAA /* Sources */ = { 248 | isa = PBXSourcesBuildPhase; 249 | buildActionMask = 2147483647; 250 | files = ( 251 | 9F39E711180A9DE0008FDAAA /* PrayTime.m in Sources */, 252 | 9F39E70A180A9DD0008FDAAA /* Tests.m in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | /* End PBXSourcesBuildPhase section */ 257 | 258 | /* Begin PBXTargetDependency section */ 259 | 9F39E70D180A9DD0008FDAAA /* PBXTargetDependency */ = { 260 | isa = PBXTargetDependency; 261 | target = 9F39E6A41809D02C008FDAAA /* OCPrayerTimes */; 262 | targetProxy = 9F39E70C180A9DD0008FDAAA /* PBXContainerItemProxy */; 263 | }; 264 | /* End PBXTargetDependency section */ 265 | 266 | /* Begin PBXVariantGroup section */ 267 | 9F39E706180A9DD0008FDAAA /* InfoPlist.strings */ = { 268 | isa = PBXVariantGroup; 269 | children = ( 270 | 9F39E707180A9DD0008FDAAA /* en */, 271 | ); 272 | name = InfoPlist.strings; 273 | sourceTree = ""; 274 | }; 275 | /* End PBXVariantGroup section */ 276 | 277 | /* Begin XCBuildConfiguration section */ 278 | 9F39E6B11809D02C008FDAAA /* Debug */ = { 279 | isa = XCBuildConfiguration; 280 | buildSettings = { 281 | ALWAYS_SEARCH_USER_PATHS = NO; 282 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 283 | CLANG_CXX_LIBRARY = "libc++"; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_WARN_BOOL_CONVERSION = YES; 286 | CLANG_WARN_CONSTANT_CONVERSION = YES; 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 288 | CLANG_WARN_EMPTY_BODY = YES; 289 | CLANG_WARN_ENUM_CONVERSION = YES; 290 | CLANG_WARN_INT_CONVERSION = YES; 291 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 292 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 293 | COPY_PHASE_STRIP = NO; 294 | GCC_C_LANGUAGE_STANDARD = gnu99; 295 | GCC_DYNAMIC_NO_PIC = NO; 296 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 297 | GCC_OPTIMIZATION_LEVEL = 0; 298 | GCC_PREPROCESSOR_DEFINITIONS = ( 299 | "DEBUG=1", 300 | "$(inherited)", 301 | ); 302 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 303 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 304 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 305 | GCC_WARN_UNDECLARED_SELECTOR = YES; 306 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 307 | GCC_WARN_UNUSED_FUNCTION = YES; 308 | GCC_WARN_UNUSED_VARIABLE = YES; 309 | MACOSX_DEPLOYMENT_TARGET = 10.9; 310 | ONLY_ACTIVE_ARCH = YES; 311 | SDKROOT = macosx; 312 | }; 313 | name = Debug; 314 | }; 315 | 9F39E6B21809D02C008FDAAA /* Release */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ALWAYS_SEARCH_USER_PATHS = NO; 319 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 320 | CLANG_CXX_LIBRARY = "libc++"; 321 | CLANG_ENABLE_OBJC_ARC = YES; 322 | CLANG_WARN_BOOL_CONVERSION = YES; 323 | CLANG_WARN_CONSTANT_CONVERSION = YES; 324 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 325 | CLANG_WARN_EMPTY_BODY = YES; 326 | CLANG_WARN_ENUM_CONVERSION = YES; 327 | CLANG_WARN_INT_CONVERSION = YES; 328 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 329 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 330 | COPY_PHASE_STRIP = YES; 331 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 332 | ENABLE_NS_ASSERTIONS = NO; 333 | GCC_C_LANGUAGE_STANDARD = gnu99; 334 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 335 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 336 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 337 | GCC_WARN_UNDECLARED_SELECTOR = YES; 338 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 339 | GCC_WARN_UNUSED_FUNCTION = YES; 340 | GCC_WARN_UNUSED_VARIABLE = YES; 341 | MACOSX_DEPLOYMENT_TARGET = 10.9; 342 | SDKROOT = macosx; 343 | }; 344 | name = Release; 345 | }; 346 | 9F39E6B41809D02C008FDAAA /* Debug */ = { 347 | isa = XCBuildConfiguration; 348 | buildSettings = { 349 | CLANG_ENABLE_OBJC_ARC = YES; 350 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 351 | GCC_PREFIX_HEADER = "OCPrayerTimes/OCPrayerTimes-Prefix.pch"; 352 | MACOSX_DEPLOYMENT_TARGET = 10.8; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | }; 355 | name = Debug; 356 | }; 357 | 9F39E6B51809D02C008FDAAA /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | CLANG_ENABLE_OBJC_ARC = YES; 361 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 362 | GCC_PREFIX_HEADER = "OCPrayerTimes/OCPrayerTimes-Prefix.pch"; 363 | MACOSX_DEPLOYMENT_TARGET = 10.8; 364 | PRODUCT_NAME = "$(TARGET_NAME)"; 365 | }; 366 | name = Release; 367 | }; 368 | 9F39E70F180A9DD0008FDAAA /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | FRAMEWORK_SEARCH_PATHS = ( 372 | "$(DEVELOPER_FRAMEWORKS_DIR)", 373 | "$(inherited)", 374 | ); 375 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 376 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 377 | GCC_PREPROCESSOR_DEFINITIONS = ( 378 | "DEBUG=1", 379 | "$(inherited)", 380 | ); 381 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 382 | MACOSX_DEPLOYMENT_TARGET = 10.8; 383 | PRODUCT_NAME = "$(TARGET_NAME)"; 384 | WRAPPER_EXTENSION = xctest; 385 | }; 386 | name = Debug; 387 | }; 388 | 9F39E710180A9DD0008FDAAA /* Release */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | FRAMEWORK_SEARCH_PATHS = ( 392 | "$(DEVELOPER_FRAMEWORKS_DIR)", 393 | "$(inherited)", 394 | ); 395 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 396 | GCC_PREFIX_HEADER = "Tests/Tests-Prefix.pch"; 397 | INFOPLIST_FILE = "Tests/Tests-Info.plist"; 398 | MACOSX_DEPLOYMENT_TARGET = 10.8; 399 | PRODUCT_NAME = "$(TARGET_NAME)"; 400 | WRAPPER_EXTENSION = xctest; 401 | }; 402 | name = Release; 403 | }; 404 | /* End XCBuildConfiguration section */ 405 | 406 | /* Begin XCConfigurationList section */ 407 | 9F39E6A01809D02C008FDAAA /* Build configuration list for PBXProject "OCPrayerTimes" */ = { 408 | isa = XCConfigurationList; 409 | buildConfigurations = ( 410 | 9F39E6B11809D02C008FDAAA /* Debug */, 411 | 9F39E6B21809D02C008FDAAA /* Release */, 412 | ); 413 | defaultConfigurationIsVisible = 0; 414 | defaultConfigurationName = Release; 415 | }; 416 | 9F39E6B31809D02C008FDAAA /* Build configuration list for PBXNativeTarget "OCPrayerTimes" */ = { 417 | isa = XCConfigurationList; 418 | buildConfigurations = ( 419 | 9F39E6B41809D02C008FDAAA /* Debug */, 420 | 9F39E6B51809D02C008FDAAA /* Release */, 421 | ); 422 | defaultConfigurationIsVisible = 0; 423 | defaultConfigurationName = Release; 424 | }; 425 | 9F39E70E180A9DD0008FDAAA /* Build configuration list for PBXNativeTarget "Tests" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | 9F39E70F180A9DD0008FDAAA /* Debug */, 429 | 9F39E710180A9DD0008FDAAA /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | /* End XCConfigurationList section */ 435 | }; 436 | rootObject = 9F39E69D1809D02C008FDAAA /* Project object */; 437 | } 438 | -------------------------------------------------------------------------------- /OCPrayerTimes/PrayTime.m: -------------------------------------------------------------------------------- 1 | // 2 | // PrayTime.m 3 | // OCPrayerTimes 4 | // 5 | // Created by Sumardi Shukor on 10/13/13. 6 | // Copyright (c) 2013 Software Machine Development. All rights reserved. 7 | // 8 | // Modified version of the original source code written by Hussain Ali. 9 | // Converted to the Modern Objective-C Syntax. 10 | // 11 | // Objective C Code By: Hussain Ali Khan 12 | // Original JS Code By: Hamid Zarrabi-Zadeh 13 | // Original Source from : PrayTimes.org 14 | // 15 | // OCPrayerTimes podspec created and maintained by: 16 | // Sumardi Shukor 17 | // https://www.github.com/sumardi/OCPrayerTimes 18 | // 19 | 20 | #import "PrayTime.h" 21 | 22 | @interface PrayTime () { 23 | // caculation method 24 | CalculationMethod calcMethod; 25 | 26 | // juristic method 27 | JuristicMethod asrJuristic; 28 | 29 | // minutes after mid-day for Dhuhr 30 | NSInteger dhuhrMinutes; 31 | 32 | // adjusting method for higher latitudes 33 | AdjustMethodHigherLatitude adjustHighLats; 34 | 35 | // time format 36 | TimeFormat timeFormat; 37 | 38 | double lat; // latitude 39 | double lng; // longitude 40 | double timeZone; // time-zone 41 | double jDate; // Julian date 42 | } 43 | 44 | - (double)radiansToDegrees:(double)alpha; 45 | - (double)degreesToRadians:(double)alpha; 46 | - (double)fixangle:(double)a; 47 | - (double)fixhour:(double)a; 48 | - (double)dsin:(double)d; 49 | - (double)dcos:(double)d; 50 | - (double)dtan:(double)d; 51 | - (double)darcsin:(double)x; 52 | - (double)darccos:(double)x; 53 | - (double)darctan:(double)x; 54 | - (double)darccot:(double)x; 55 | - (double)darctan2:(double)y andX:(double)x; 56 | 57 | - (double)getBaseTimeZone; 58 | - (double)detectDaylightSaving; 59 | 60 | - (double)julianDateForYear:(NSInteger)year month:(NSInteger)month andDay:(NSInteger)day; 61 | - (double)calculateJulianDateForYear:(NSInteger)year month:(NSInteger)month andDay:(NSInteger)day; 62 | 63 | - (NSMutableArray *)sunPosition:(double)jd; 64 | - (double)equationOfTime:(double)jd; 65 | - (double)sunDeclination:(double)jd; 66 | - (double)computeMidDay:(double)t; 67 | - (double)computeTime:(double)t andAngle:(double)g; 68 | - (double)computeAsr:(double)step andTime:(double)t; 69 | 70 | - (double)timeDiff:(double)time1 andTime2:(double)time2; 71 | 72 | - (NSMutableArray *)computeTimes:(NSMutableArray *)times; 73 | - (NSMutableArray *)computeDayTimes; 74 | - (NSMutableArray *)adjustTimes:(NSMutableArray *)times; 75 | - (NSMutableArray *)adjustTimesFormat:(NSMutableArray *)times; 76 | - (NSMutableArray *)adjustHighLatTimes:(NSMutableArray *)times; 77 | - (double)nightPortion:(double)angle; 78 | - (NSMutableArray *)dayPortion:(NSMutableArray*)times; 79 | - (void)tune:(NSMutableDictionary*)offsetTimes; 80 | - (NSMutableArray *)tuneTimes:(NSMutableArray *)times; 81 | 82 | - (NSString *)floatToTime24:(double)time; 83 | - (NSString *)floatToTime12:(double)time suffix:(BOOL)f; 84 | - (NSString *)floatToTime12NS:(double)time; 85 | 86 | @end 87 | 88 | @implementation PrayTime 89 | 90 | #pragma mark - Creating, Copying and Deallocating Object 91 | 92 | - (id)init 93 | { 94 | if(self = [super init]) { 95 | 96 | // Default 97 | calcMethod = CalculationMethodJafari; 98 | asrJuristic = JuristicMethodShafii; 99 | dhuhrMinutes = 0; 100 | adjustHighLats = AdjustMethodHigherLatitudeMidNight; 101 | timeFormat = TimeFormat24Hour; 102 | 103 | // Time Names 104 | timeNames = [@[@"Fajr", @"Sunrise", @"Dhuhr", @"Asr", @"Sunset", @"Maghrib", @"Isha"] mutableCopy]; 105 | 106 | InvalidTime = @"-----"; // The string used for invalid times 107 | 108 | //--------------------- Technical Settings -------------------- 109 | 110 | numIterations = 1; // number of iterations needed to compute times 111 | 112 | //------------------- Calc Method Parameters -------------------- 113 | 114 | // Tuning offsets 115 | offsets = [@[@0, 116 | @0, 117 | @0, 118 | @0, 119 | @0, 120 | @0, 121 | @0] mutableCopy]; 122 | 123 | /* 124 | fa : fajr angle 125 | ms : maghrib selector (0 = angle; 1 = minutes after sunset) 126 | mv : maghrib parameter value (in angle or minutes) 127 | is : isha selector (0 = angle; 1 = minutes after maghrib) 128 | iv : isha parameter value (in angle or minutes) 129 | */ 130 | methodParams = [NSMutableDictionary dictionary]; 131 | 132 | methodParams[@(CalculationMethodJafari)] = @[@16, 133 | @0, 134 | @4, 135 | @0, 136 | @14]; 137 | 138 | methodParams[@(CalculationMethodKarachi)] = @[@18, 139 | @1, 140 | @0, 141 | @0, 142 | @18]; 143 | 144 | methodParams[@(CalculationMethodISNA)] = @[@15, 145 | @1, 146 | @0, 147 | @0, 148 | @15]; 149 | 150 | methodParams[@(CalculationMethodMWL)] = @[@18, 151 | @1, 152 | @0, 153 | @0, 154 | @17]; 155 | 156 | methodParams[@(CalculationMethodMakkah)] = @[@18.5, 157 | @1, 158 | @0, 159 | @1, 160 | @90]; 161 | 162 | methodParams[@(CalculationMethodEgypt)] = @[@19.5, 163 | @1, 164 | @0, 165 | @0, 166 | @17.5]; 167 | 168 | methodParams[@(CalculationMethodTehran)] = @[@17.7, 169 | @0, 170 | @4.5, 171 | @0, 172 | @14]; 173 | 174 | methodParams[@(CalculationMethodCustom)] = @[@18, 175 | @1, 176 | @0, 177 | @0, 178 | @17]; 179 | 180 | } 181 | 182 | return self; 183 | } 184 | 185 | - (id)initWithJuristic:(JuristicMethod)juristic andCalculation:(CalculationMethod)calculation 186 | { 187 | if (self = [self init]) { 188 | [self setJuristicMethod:juristic]; 189 | [self setCalculationMethod:calculation]; 190 | } 191 | 192 | return self; 193 | } 194 | 195 | #pragma mark - Trigonometric Methods 196 | 197 | // range reduce angle in degrees. 198 | - (double)fixangle:(double)a 199 | { 200 | a = a - (360 * (floor(a / 360.0))); 201 | a = a < 0 ? (a + 360) : a; 202 | 203 | return a; 204 | } 205 | 206 | // range reduce hours to 0..23 207 | - (double)fixhour:(double)a 208 | { 209 | a = a - 24.0 * floor(a / 24.0); 210 | a = a < 0 ? (a + 24) : a; 211 | 212 | return a; 213 | } 214 | 215 | // radian to degree 216 | - (double)radiansToDegrees:(double)alpha 217 | { 218 | return ((alpha * 180.0)/M_PI); 219 | } 220 | 221 | // degree to radian 222 | - (double)degreesToRadians:(double)alpha 223 | { 224 | return ((alpha * M_PI)/180.0); 225 | } 226 | 227 | // degree sin 228 | - (double)dsin:(double)d 229 | { 230 | return (sin([self degreesToRadians:d])); 231 | } 232 | 233 | // degree cos 234 | - (double)dcos:(double)d 235 | { 236 | return (cos([self degreesToRadians:d])); 237 | } 238 | 239 | // degree tan 240 | - (double)dtan:(double)d 241 | { 242 | return (tan([self degreesToRadians:d])); 243 | } 244 | 245 | // degree arcsin 246 | - (double)darcsin:(double)x 247 | { 248 | double val = asin(x); 249 | return [self radiansToDegrees:val]; 250 | } 251 | 252 | // degree arccos 253 | - (double)darccos:(double)x 254 | { 255 | double val = acos(x); 256 | return [self radiansToDegrees:val]; 257 | } 258 | 259 | // degree arctan 260 | - (double)darctan:(double)x 261 | { 262 | double val = atan(x); 263 | return [self radiansToDegrees:val]; 264 | } 265 | 266 | // degree arctan2 267 | - (double)darctan2:(double)y andX:(double)x 268 | { 269 | double val = atan2(y, x); 270 | return [self radiansToDegrees:val]; 271 | } 272 | 273 | // degree arccot 274 | - (double)darccot:(double)x 275 | { 276 | double val = atan2(1.0, x); 277 | return [self radiansToDegrees:val]; 278 | } 279 | 280 | #pragma mark - Timezone Methods 281 | 282 | // compute local time-zone for a specific date 283 | - (double)getTimeZone 284 | { 285 | NSTimeZone *_timeZone = [NSTimeZone localTimeZone]; 286 | double hoursDiff = [_timeZone secondsFromGMT]/3600.0f; 287 | 288 | return hoursDiff; 289 | } 290 | 291 | // compute base time-zone of the system 292 | - (double)getBaseTimeZone 293 | { 294 | NSTimeZone *_timeZone = [NSTimeZone defaultTimeZone]; 295 | double hoursDiff = [_timeZone secondsFromGMT]/3600.0f; 296 | 297 | return hoursDiff; 298 | } 299 | 300 | // detect daylight saving in a given date 301 | - (double)detectDaylightSaving 302 | { 303 | NSTimeZone *_timeZone = [NSTimeZone localTimeZone]; 304 | double hoursDiff = [_timeZone daylightSavingTimeOffsetForDate:[NSDate date]]; 305 | 306 | return hoursDiff; 307 | } 308 | 309 | // get the hours diff from timezone 310 | - (double)getHoursDiffFromTimezone:(NSTimeZone *)timezone 311 | { 312 | return [timezone secondsFromGMT]/3600.0f; 313 | } 314 | 315 | #pragma mark - Julian Date Methods 316 | 317 | // calculate julian date from a calendar date 318 | - (double)julianDateForYear:(NSInteger)year month:(NSInteger)month andDay:(NSInteger)day 319 | { 320 | if (month <= 2) { 321 | year -= 1; 322 | month += 12; 323 | } 324 | 325 | double A = floor(year/100.0); 326 | double B = 2 - A + floor(A/4.0); 327 | double JD = floor(365.25 * (year+ 4716)) + floor(30.6001 * (month + 1)) + day + B - 1524.5; 328 | 329 | return JD; 330 | } 331 | 332 | // convert a calendar date to julian date (second method) 333 | - (double)calculateJulianDateForYear:(NSInteger)year month:(NSInteger)month andDay:(NSInteger)day 334 | { 335 | double J1970 = 2440588; 336 | NSDateComponents *components = [[NSDateComponents alloc] init]; 337 | [components setWeekday:day]; // Monday 338 | //[components setWeekdayOrdinal:1]; // The first day in the month 339 | [components setMonth:month]; // May 340 | [components setYear:year]; 341 | NSCalendar *gregorian = [[NSCalendar alloc] 342 | initWithCalendarIdentifier:NSGregorianCalendar]; 343 | NSDate *date1 = [gregorian dateFromComponents:components]; 344 | 345 | double ms = [date1 timeIntervalSince1970];// # of milliseconds since midnight Jan 1, 1970 346 | double days = floor(ms/ (1000.0 * 60.0 * 60.0 * 24.0)); 347 | 348 | return J1970+ days- 0.5; 349 | } 350 | 351 | #pragma mark - Calculation Methods 352 | 353 | /* 354 | References: 355 | http://www.ummah.net/astronomy/saltime 356 | http://aa.usno.navy.mil/faq/docs/SunApprox.html 357 | */ 358 | 359 | // compute declination angle of sun and equation of time 360 | - (NSMutableArray *)sunPosition:(double)jd 361 | { 362 | double D = jd - 2451545; 363 | double g = [self fixangle: (357.529 + 0.98560028 * D)]; 364 | double q = [self fixangle: (280.459 + 0.98564736 * D)]; 365 | double L = [self fixangle: (q + (1.915 * [self dsin: g]) + (0.020 * [self dsin:(2 * g)]))]; 366 | 367 | // double R = 1.00014 - 0.01671 * [self dcos:g] - 0.00014 * [self dcos: (2*g)]; 368 | double e = 23.439 - (0.00000036 * D); 369 | double d = [self darcsin: ([self dsin: e] * [self dsin: L])]; 370 | double RA = ([self darctan2: ([self dcos: e] * [self dsin: L]) andX: [self dcos:L]])/ 15.0; 371 | RA = [self fixhour:RA]; 372 | 373 | double EqT = q/15.0 - RA; 374 | 375 | NSMutableArray *sPosition = [[NSMutableArray alloc] init]; 376 | [sPosition addObject:@(d)]; 377 | [sPosition addObject:@(EqT)]; 378 | 379 | return sPosition; 380 | } 381 | 382 | // compute equation of time 383 | - (double)equationOfTime:(double)jd 384 | { 385 | double eq = [[self sunPosition:jd][1] doubleValue]; 386 | 387 | return eq; 388 | } 389 | 390 | // compute declination angle of sun 391 | - (double)sunDeclination:(double)jd 392 | { 393 | double d = [[self sunPosition:jd][0] doubleValue]; 394 | 395 | return d; 396 | } 397 | 398 | // compute mid-day (Dhuhr, Zawal) time 399 | - (double)computeMidDay:(double)t 400 | { 401 | double T = [self equationOfTime:(jDate+ t)]; 402 | double Z = [self fixhour: (12 - T)]; 403 | 404 | return Z; 405 | } 406 | 407 | // compute time for a given angle G 408 | - (double)computeTime:(double)t andAngle:(double)g 409 | { 410 | double D = [self sunDeclination:(jDate+ t)]; 411 | double Z = [self computeMidDay: t]; 412 | double V = ([self darccos: (-[self dsin:g] - ([self dsin:D] * [self dsin:lat]))/ ([self dcos:D] * [self dcos:lat])]) / 15.0f; 413 | 414 | return Z+ (g>90 ? -V : V); 415 | } 416 | 417 | // compute the time of Asr 418 | // Shafii: step=1, Hanafi: step=2 419 | - (double)computeAsr:(double)step andTime:(double)t 420 | { 421 | double D = [self sunDeclination:(jDate+ t)]; 422 | double G = -[self darccot : (step + [self dtan:ABS(lat-D)])]; 423 | 424 | return [self computeTime:t andAngle:G]; 425 | } 426 | 427 | #pragma mark - Misc. Methods 428 | 429 | // compute the difference between two times 430 | - (double)timeDiff:(double)time1 andTime2:(double)time2 431 | { 432 | return [self fixhour:(time2- time1)]; 433 | } 434 | 435 | #pragma mark - Interface Methods 436 | 437 | // return prayer times for a given date 438 | - (NSMutableArray *)getDatePrayerTimesForYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day latitude:(double)latitude longitude:(double)longitude andtimeZone:(double)tZone 439 | { 440 | lat = latitude; 441 | lng = longitude; 442 | 443 | timeZone = tZone; 444 | jDate = [self julianDateForYear:year month:month andDay:day]; 445 | 446 | double lonDiff = longitude/(15.0 * 24.0); 447 | jDate = jDate - lonDiff; 448 | return [self computeDayTimes]; 449 | } 450 | 451 | // return prayer times for a given date 452 | - (NSMutableArray *)getPrayerTimesForDate:(NSDateComponents *)date withLatitude:(double)latitude longitude:(double)longitude andTimeZone:(double)tZone 453 | { 454 | NSInteger year = [date year]; 455 | NSInteger month = [date month]; 456 | NSInteger day = [date day]; 457 | 458 | return [self getDatePrayerTimesForYear:year month:month day:day latitude:latitude longitude:longitude andtimeZone:tZone]; 459 | } 460 | 461 | // return prayer times for the given date 462 | - (NSMutableArray *)prayerTimesDate:(NSDate *)date latitude:(double)latitude longitude:(double)longitude andTimezone:(double)timezone 463 | { 464 | unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; 465 | NSCalendar *calendar = [NSCalendar currentCalendar]; 466 | NSDateComponents *components = [calendar components:unitFlags fromDate:date]; 467 | 468 | NSInteger year = [components year]; 469 | NSInteger month = [components month]; 470 | NSInteger day = [components day]; 471 | 472 | return [self getDatePrayerTimesForYear:year month:month day:day latitude:latitude longitude:longitude andtimeZone:timezone]; 473 | } 474 | 475 | // return current prayer times from the given location 476 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location 477 | { 478 | return [self prayerTimesFromLocation:location forDate:location.timestamp]; 479 | } 480 | 481 | // return prayer times from the given location 482 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location forDate:(NSDate *)date 483 | { 484 | return [self prayerTimesDate:date 485 | latitude:location.coordinate.latitude 486 | longitude:location.coordinate.longitude 487 | andTimezone:[self getTimeZone]]; 488 | } 489 | 490 | // return prayer times from the given location and timezone 491 | - (NSMutableArray *)prayerTimesFromLocation:(CLLocation *)location forDate:(NSDate *)date timezone:(NSTimeZone *)timezone 492 | { 493 | return [self prayerTimesDate:date 494 | latitude:location.coordinate.latitude 495 | longitude:location.coordinate.longitude 496 | andTimezone:[self getHoursDiffFromTimezone:timezone]]; 497 | } 498 | 499 | // set the calculation method 500 | - (void)setCalculationMethod:(CalculationMethod)method 501 | { 502 | switch (method) { 503 | case CalculationMethodJafari: 504 | case CalculationMethodKarachi: 505 | case CalculationMethodISNA: 506 | case CalculationMethodMWL: 507 | case CalculationMethodMakkah: 508 | case CalculationMethodEgypt: 509 | case CalculationMethodTehran: 510 | case CalculationMethodCustom: 511 | calcMethod = method; 512 | break; 513 | 514 | default: 515 | return; 516 | break; 517 | } 518 | } 519 | 520 | // set the juristic method for Asr 521 | - (void)setJuristicMethod:(JuristicMethod)method 522 | { 523 | switch (method) { 524 | case JuristicMethodShafii: 525 | case JuristicMethodHanafi: 526 | asrJuristic = method; 527 | break; 528 | 529 | default: 530 | return; 531 | break; 532 | } 533 | } 534 | 535 | // set custom values for calculation parameters 536 | - (void)setCustomParams:(NSMutableArray *)params 537 | { 538 | methodParams[@(CalculationMethodCustom)] = params; 539 | calcMethod = CalculationMethodCustom; 540 | } 541 | 542 | // set the angle for calculating Fajr 543 | - (void)setFajrAngle:(double)angle 544 | { 545 | [self setCustomParams:[@[@(angle), 546 | @-1.0, 547 | @-1.0, 548 | @-1.0, 549 | @-1.0] mutableCopy]]; 550 | } 551 | 552 | // set the angle for calculating Maghrib 553 | - (void)setMaghribAngle:(double)angle 554 | { 555 | [self setCustomParams:[@[@-1.0, 556 | @0.0, 557 | @(angle), 558 | @-1.0, 559 | @-1.0] mutableCopy]]; 560 | } 561 | 562 | // set the angle for calculating Isha 563 | - (void)setIshaAngle:(double)angle 564 | { 565 | [self setCustomParams:[@[@-1.0, 566 | @-1.0, 567 | @-1.0, 568 | @0.0, 569 | @(angle)] mutableCopy]]; 570 | } 571 | 572 | // set the minutes after mid-day for calculating Dhuhr 573 | - (void)setDhuhrMinutes:(double)minutes 574 | { 575 | dhuhrMinutes = minutes; 576 | } 577 | 578 | // set the minutes after Sunset for calculating Maghrib 579 | - (void)setMaghribMinutes:(double)minutes 580 | { 581 | [self setCustomParams:[@[@-1.0, 582 | @1.0, 583 | @(minutes), 584 | @-1.0, 585 | @-1.0] mutableCopy]]; 586 | } 587 | 588 | // set the minutes after Maghrib for calculating Isha 589 | - (void)setIshaMinutes:(double)minutes 590 | { 591 | [self setCustomParams:[@[@-1.0, 592 | @-1.0, 593 | @-1.0, 594 | @1.0, 595 | @(minutes)] mutableCopy]]; 596 | } 597 | 598 | // set adjusting method for higher latitudes 599 | - (void)setHighLatitudsMethod:(AdjustMethodHigherLatitude)method 600 | { 601 | switch (method) { 602 | case AdjustMethodHigherLatitudeNone: 603 | case AdjustMethodHigherLatitudeMidNight: 604 | case AdjustMethodHigherLatitudeOneSevent: 605 | case AdjustMethodHigherLatitudeAngleBased: 606 | adjustHighLats = method; 607 | break; 608 | 609 | default: 610 | return; 611 | break; 612 | } 613 | } 614 | 615 | // set the time format 616 | - (void)setTimeFormat:(TimeFormat)format 617 | { 618 | switch (format) { 619 | case TimeFormat24Hour: 620 | case TimeFormat12Hour: 621 | case TimeFormat12WithNoSuffix: 622 | case TimeFormatFloat: 623 | timeFormat = format; 624 | break; 625 | 626 | default: 627 | return; 628 | break; 629 | } 630 | } 631 | 632 | // convert double hours to 24h format 633 | - (NSString *)floatToTime24:(double)time 634 | { 635 | NSString *result = nil; 636 | 637 | if (isnan(time)) 638 | return InvalidTime; 639 | 640 | time = [self fixhour:(time + 0.5/ 60.0)]; // add 0.5 minutes to round 641 | int hours = floor(time); 642 | double minutes = floor((time - hours) * 60.0); 643 | 644 | if((hours >=0 && hours<=9) && (minutes >=0 && minutes <=9)){ 645 | result = [NSString stringWithFormat:@"0%d:0%.0f",hours, minutes]; 646 | } 647 | else if((hours >=0 && hours<=9)){ 648 | result = [NSString stringWithFormat:@"0%d:%.0f",hours, minutes]; 649 | } 650 | else if((minutes >=0 && minutes <=9)){ 651 | result = [NSString stringWithFormat:@"%d:0%.0f",hours, minutes]; 652 | } 653 | else{ 654 | result = [NSString stringWithFormat:@"%d:%.0f",hours, minutes]; 655 | } 656 | 657 | return result; 658 | } 659 | 660 | // convert double hours to 12h format 661 | - (NSString *)floatToTime12:(double)time suffix:(BOOL)f 662 | { 663 | if (isnan(time)) 664 | return InvalidTime; 665 | 666 | time =[self fixhour:(time+ 0.5/ 60)]; // add 0.5 minutes to round 667 | double hours = floor(time); 668 | double minutes = floor((time- hours)* 60); 669 | NSString *suffix, *result=nil; 670 | if(hours >= 12) { 671 | suffix = @"pm"; 672 | } 673 | else{ 674 | suffix = @"am"; 675 | } 676 | //hours = ((((hours+ 12) -1) % (12))+ 1); 677 | hours = (hours + 12) - 1; 678 | int hrs = (int)hours % 12; 679 | hrs += 1; 680 | if(f == YES){ 681 | if((hrs >=0 && hrs<=9) && (minutes >=0 && minutes <=9)){ 682 | result = [NSString stringWithFormat:@"0%d:0%.0f %@",hrs, minutes, suffix]; 683 | } 684 | else if((hrs >=0 && hrs<=9)){ 685 | result = [NSString stringWithFormat:@"0%d:%.0f %@",hrs, minutes, suffix]; 686 | } 687 | else if((minutes >=0 && minutes <=9)){ 688 | result = [NSString stringWithFormat:@"%d:0%.0f %@",hrs, minutes, suffix]; 689 | } 690 | else{ 691 | result = [NSString stringWithFormat:@"%d:%.0f %@",hrs, minutes, suffix]; 692 | } 693 | 694 | } 695 | else{ 696 | if((hrs >=0 && hrs<=9) && (minutes >=0 && minutes <=9)){ 697 | result = [NSString stringWithFormat:@"0%d:0%.0f",hrs, minutes]; 698 | } 699 | else if((hrs >=0 && hrs<=9)){ 700 | result = [NSString stringWithFormat:@"0%d:%.0f",hrs, minutes]; 701 | } 702 | else if((minutes >=0 && minutes <=9)){ 703 | result = [NSString stringWithFormat:@"%d:0%.0f",hrs, minutes]; 704 | } 705 | else{ 706 | result = [NSString stringWithFormat:@"%d:%.0f",hrs, minutes]; 707 | } 708 | } 709 | 710 | return result; 711 | } 712 | 713 | // convert double hours to 12h format with no suffix 714 | - (NSString *)floatToTime12NS:(double)time 715 | { 716 | return [self floatToTime12:TimeFormatFloat suffix:NO]; 717 | } 718 | 719 | #pragma mark - Compute Prayer Times 720 | 721 | // compute prayer times at given julian date 722 | - (NSMutableArray *)computeTimes:(NSMutableArray *)times 723 | { 724 | NSMutableArray *t = [self dayPortion:times]; 725 | 726 | id obj = methodParams[[NSNumber numberWithInt:calcMethod]]; 727 | double idk = [obj[0] doubleValue]; 728 | double Fajr = [self computeTime:[t[0] doubleValue] andAngle:(180 - idk)]; 729 | double Sunrise = [self computeTime:[t[1] doubleValue] andAngle:(180 - 0.833)]; 730 | double Dhuhr = [self computeMidDay: [t[2] doubleValue]]; 731 | double Asr = [self computeAsr:(1 + asrJuristic) andTime: [t[3] doubleValue]]; 732 | double Sunset = [self computeTime: [t[4] doubleValue] andAngle:0.833]; 733 | double Maghrib = [self computeTime:[t[5] doubleValue] andAngle:[methodParams[[NSNumber numberWithInt:calcMethod]][2] doubleValue]]; 734 | double Isha = [self computeTime:[t[6] doubleValue] andAngle:[methodParams[[NSNumber numberWithInt:calcMethod]][4] doubleValue]]; 735 | 736 | NSMutableArray *Ctimes = [@[@(Fajr), 737 | @(Sunrise), 738 | @(Dhuhr), 739 | @(Asr), 740 | @(Sunset), 741 | @(Maghrib), 742 | @(Isha)] mutableCopy]; 743 | 744 | return Ctimes; 745 | } 746 | 747 | // compute prayer times at given julian date 748 | - (NSMutableArray*)computeDayTimes 749 | { 750 | //int i = 0; 751 | NSMutableArray *t1, *t2, *t3; 752 | 753 | //default times 754 | NSMutableArray *times = [@[@5.0, 755 | @6.0, 756 | @12.0, 757 | @13.0, 758 | @18.0, 759 | @18.0, 760 | @18.0] mutableCopy]; 761 | 762 | for (int i=1; i<= numIterations; i++) 763 | t1 = [self computeTimes:times]; 764 | 765 | t2 = [self adjustTimes:t1]; 766 | 767 | t2 = [self tuneTimes:t2]; 768 | 769 | //Set prayerTimesCurrent here!! 770 | prayerTimesCurrent = [[NSMutableArray alloc] initWithArray:t2]; 771 | 772 | t3 = [self adjustTimesFormat:t2]; 773 | 774 | return t3; 775 | } 776 | 777 | //Tune timings for adjustments 778 | //Set time offsets 779 | - (void)tune:(NSMutableDictionary*)offsetTimes 780 | { 781 | offsets[0] = offsetTimes[@"fajr"]; 782 | offsets[1] = offsetTimes[@"sunrise"]; 783 | offsets[2] = offsetTimes[@"dhuhr"]; 784 | offsets[3] = offsetTimes[@"asr"]; 785 | offsets[4] = offsetTimes[@"sunset"]; 786 | offsets[5] = offsetTimes[@"maghrib"]; 787 | offsets[6] = offsetTimes[@"isha"]; 788 | } 789 | 790 | - (NSMutableArray *)tuneTimes:(NSMutableArray *)times 791 | { 792 | double off, time; 793 | for(int i=0; i<[times count]; i++){ 794 | //if(i==5) 795 | //NSLog(@"Normal: %d - %@", i, [times objectAtIndex:i]); 796 | off = [offsets[i] doubleValue]/60.0; 797 | time = [times[i] doubleValue] + off; 798 | times[i] = @(time); 799 | //if(i==5) 800 | //NSLog(@"Modified: %d - %@", i, [times objectAtIndex:i]); 801 | } 802 | 803 | return times; 804 | } 805 | 806 | // adjust times in a prayer time array 807 | - (NSMutableArray *)adjustTimes:(NSMutableArray *)times 808 | { 809 | int i = 0; 810 | NSMutableArray *a; //test variable 811 | double time = 0, Dtime, Dtime1, Dtime2; 812 | 813 | for (i=0; i<7; i++) { 814 | time = ([times[i] doubleValue]) + (timeZone- lng/ 15.0); 815 | 816 | times[i] = @(time); 817 | 818 | } 819 | 820 | Dtime = [times[2] doubleValue] + (dhuhrMinutes/ 60.0); //Dhuhr 821 | 822 | times[2] = @(Dtime); 823 | 824 | a = methodParams[[NSNumber numberWithInt:calcMethod]]; 825 | double val = [a[1] doubleValue]; 826 | 827 | if (val == 1) { // Maghrib 828 | Dtime1 = [times[4] doubleValue]+ ([methodParams[[NSNumber numberWithInt:calcMethod]][2] doubleValue]/60.0); 829 | times[5] = @(Dtime1); 830 | } 831 | 832 | if ([methodParams[[NSNumber numberWithInt:calcMethod]][3] doubleValue]== 1) { // Isha 833 | Dtime2 = [times[5] doubleValue] + ([methodParams[[NSNumber numberWithInt:calcMethod]][4] doubleValue]/60.0); 834 | times[6] = @(Dtime2); 835 | } 836 | 837 | if (adjustHighLats != AdjustMethodHigherLatitudeNone){ 838 | times = [self adjustHighLatTimes:times]; 839 | } 840 | 841 | return times; 842 | } 843 | 844 | // convert times array to given time format 845 | - (NSMutableArray *)adjustTimesFormat:(NSMutableArray *)times 846 | { 847 | int i = 0; 848 | 849 | if (timeFormat == TimeFormatFloat){ 850 | return times; 851 | } 852 | 853 | for (i=0; i<7; i++) { 854 | if (timeFormat == TimeFormat12Hour){ 855 | times[i] = [self floatToTime12:[times[i] doubleValue] suffix:YES]; 856 | } 857 | else if (timeFormat == TimeFormat12WithNoSuffix){ 858 | times[i] = [self floatToTime12:[times[i] doubleValue] suffix:NO]; 859 | } 860 | else{ 861 | 862 | times[i] = [self floatToTime24:[times[i] doubleValue]]; 863 | } 864 | } 865 | 866 | return times; 867 | } 868 | 869 | // adjust Fajr, Isha and Maghrib for locations in higher latitudes 870 | - (NSMutableArray*)adjustHighLatTimes:(NSMutableArray *)times 871 | { 872 | double time0 = [times[0] doubleValue]; 873 | double time1 = [times[1] doubleValue]; 874 | //double time2 = [[times objectAtIndex:2] doubleValue]; 875 | //double time3 = [[times objectAtIndex:3] doubleValue]; 876 | double time4 = [times[4] doubleValue]; 877 | double time5 = [times[5] doubleValue]; 878 | double time6 = [times[6] doubleValue]; 879 | 880 | double nightTime = [self timeDiff:time4 andTime2:time1]; // sunset to sunrise 881 | 882 | // Adjust Fajr 883 | double obj0 =[methodParams[[NSNumber numberWithInt:calcMethod]][0] doubleValue]; 884 | double obj1 =[methodParams[[NSNumber numberWithInt:calcMethod]][1] doubleValue]; 885 | double obj2 =[methodParams[[NSNumber numberWithInt:calcMethod]][2] doubleValue]; 886 | double obj3 =[methodParams[[NSNumber numberWithInt:calcMethod]][3] doubleValue]; 887 | double obj4 =[methodParams[[NSNumber numberWithInt:calcMethod]][4] doubleValue]; 888 | 889 | double FajrDiff = [self nightPortion:obj0] * nightTime; 890 | 891 | if ((isnan(time0)) || ([self timeDiff:time0 andTime2:time1] > FajrDiff)) 892 | times[0] = @(time1 - FajrDiff); 893 | 894 | // Adjust Isha 895 | double IshaAngle = (obj3 == 0) ? obj4: 18; 896 | double IshaDiff = [self nightPortion: IshaAngle] * nightTime; 897 | if (isnan(time6) ||[self timeDiff:time4 andTime2:time6] > IshaDiff) 898 | times[6] = @(time4 + IshaDiff); 899 | 900 | 901 | // Adjust Maghrib 902 | double MaghribAngle = (obj1 == 0) ? obj2 : 4; 903 | double MaghribDiff = [self nightPortion: MaghribAngle] * nightTime; 904 | if (isnan(time5) || [self timeDiff:time4 andTime2:time5] > MaghribDiff) 905 | times[5] = @(time4 + MaghribDiff); 906 | 907 | return times; 908 | } 909 | 910 | // the night portion used for adjusting times in higher latitudes 911 | - (double)nightPortion:(double)angle 912 | { 913 | double calc = 0; 914 | 915 | switch (adjustHighLats) { 916 | case AdjustMethodHigherLatitudeAngleBased: 917 | calc = (angle)/60.0f; 918 | break; 919 | 920 | case AdjustMethodHigherLatitudeMidNight: 921 | calc = 0.5f; 922 | break; 923 | 924 | case AdjustMethodHigherLatitudeOneSevent: 925 | calc = 0.14286f; 926 | break; 927 | 928 | case AdjustMethodHigherLatitudeNone: 929 | default: 930 | break; 931 | } 932 | 933 | return calc; 934 | } 935 | 936 | // convert hours to day portions 937 | - (NSMutableArray *)dayPortion:(NSMutableArray *)times 938 | { 939 | int i = 0; 940 | double time = 0; 941 | for (i=0; i<7; i++){ 942 | time = [times[i] doubleValue]; 943 | time = time/24.0; 944 | 945 | times[i] = @(time); 946 | 947 | } 948 | 949 | return times; 950 | } 951 | 952 | @end --------------------------------------------------------------------------------