├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── Suncalc-Swift.xcworkspace
└── contents.xcworkspacedata
├── suncalc-example
├── suncalc-example.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── suncalc-example
│ ├── AppDelegate.swift
│ ├── Base.lproj
│ │ ├── LaunchScreen.xib
│ │ └── Main.storyboard
│ ├── Images.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Info.plist
│ └── ViewController.swift
└── suncalc-exampleTests
│ ├── Info.plist
│ └── suncalc_exampleTests.swift
├── suncalc-swift.podspec
└── suncalc
├── models
├── EquatorialCoordinates.swift
├── GeocentricCoordinates.swift
├── MoonIllumination.swift
├── MoonPosition.swift
├── MoonTimes.swift
└── SunPosition.swift
├── suncalc.swift
└── utils
├── Constants.swift
├── DateUtils.swift
├── MoonUtils.swift
├── PositionUtils.swift
├── SunUtils.swift
└── TimeUtils.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | .DS_Store
4 | */build/*
5 | build/
6 | *.pbxuser
7 | !default.pbxuser
8 | *.mode1v3
9 | !default.mode1v3
10 | *.mode2v3
11 | !default.mode2v3
12 | *.perspectivev3
13 | !default.perspectivev3
14 | xcuserdata
15 | xcshareddata
16 | profile
17 | *.moved-aside
18 | DerivedData
19 | *.hmap
20 | *.ipa
21 | *.xcuserstate
22 | *.xccheckout
23 |
24 | # CocoaPods
25 | Pods/
26 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: objective-c
2 | osx_image: xcode10.1
3 | script: "xcodebuild test -workspace Suncalc-Swift.xcworkspace -scheme suncalc-example -destination \"platform=iOS Simulator,name=iPhone 5s\""
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Chimani, LLC.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | suncalc-swift
2 | =============
3 |
4 | This is a swift port for iOS of https://github.com/mourner/suncalc
5 |
6 | This code is based on the original Javascript suncalc by Vladimir Agafonkin ("mourner").
7 |
8 | ```swift
9 | // get today's sunlight times for London
10 |
11 | let date:Date = Date()
12 | let sunCalc:SunCalc = SunCalc.getTimes(date, latitude: 51.5, longitude: -0.1)
13 |
14 | var formatter:DateFormatter = DateFormatter()
15 | formatter.dateFormat = "HH:mm"
16 | formatter.timeZone = TimeZone(abbreviation: "GMT")
17 | var sunriseString:String = formatter.string(from: sunCalc.sunrise)
18 | println("sunrise is at \(sunriseString)")
19 |
20 | let sunPos:SunPosition = SunCalc.getSunPosition(date, latitude: 51.5, longitude: -0.1)
21 |
22 | var sunriseAzimuth:Double = sunPos.azimuth * 180 / Constants.PI()
23 | println("sunrise azimuth: \(sunriseAzimuth)")
24 | ```
25 |
--------------------------------------------------------------------------------
/Suncalc-Swift.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 11C516BE19DDDD9200553C5A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516BD19DDDD9200553C5A /* AppDelegate.swift */; };
11 | 11C516C019DDDD9200553C5A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516BF19DDDD9200553C5A /* ViewController.swift */; };
12 | 11C516C319DDDD9200553C5A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 11C516C119DDDD9200553C5A /* Main.storyboard */; };
13 | 11C516C519DDDD9200553C5A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 11C516C419DDDD9200553C5A /* Images.xcassets */; };
14 | 11C516C819DDDD9200553C5A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 11C516C619DDDD9200553C5A /* LaunchScreen.xib */; };
15 | 11C516D419DDDD9200553C5A /* suncalc_exampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516D319DDDD9200553C5A /* suncalc_exampleTests.swift */; };
16 | 11C516E119DDDE6D00553C5A /* suncalc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516DF19DDDE6D00553C5A /* suncalc.swift */; };
17 | 11C516E219DDDE6D00553C5A /* suncalc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516DF19DDDE6D00553C5A /* suncalc.swift */; };
18 | 11C516E519DDE23600553C5A /* SunPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516E419DDE23600553C5A /* SunPosition.swift */; };
19 | 11C516E619DDE23600553C5A /* SunPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516E419DDE23600553C5A /* SunPosition.swift */; };
20 | 11C516E819DDE24500553C5A /* MoonPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516E719DDE24500553C5A /* MoonPosition.swift */; };
21 | 11C516E919DDE24500553C5A /* MoonPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516E719DDE24500553C5A /* MoonPosition.swift */; };
22 | 11C516EB19DDE25600553C5A /* MoonIllumination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516EA19DDE25600553C5A /* MoonIllumination.swift */; };
23 | 11C516EC19DDE25600553C5A /* MoonIllumination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516EA19DDE25600553C5A /* MoonIllumination.swift */; };
24 | 11C516EE19DDE26B00553C5A /* GeocentricCoordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516ED19DDE26B00553C5A /* GeocentricCoordinates.swift */; };
25 | 11C516EF19DDE26B00553C5A /* GeocentricCoordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516ED19DDE26B00553C5A /* GeocentricCoordinates.swift */; };
26 | 11C516F119DDE27C00553C5A /* EquatorialCoordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F019DDE27C00553C5A /* EquatorialCoordinates.swift */; };
27 | 11C516F219DDE27C00553C5A /* EquatorialCoordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F019DDE27C00553C5A /* EquatorialCoordinates.swift */; };
28 | 11C516F419DDE28D00553C5A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F319DDE28D00553C5A /* Constants.swift */; };
29 | 11C516F519DDE28D00553C5A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F319DDE28D00553C5A /* Constants.swift */; };
30 | 11C516F719DDE2A300553C5A /* DateUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F619DDE2A300553C5A /* DateUtils.swift */; };
31 | 11C516F819DDE2A300553C5A /* DateUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F619DDE2A300553C5A /* DateUtils.swift */; };
32 | 11C516FA19DDE2AF00553C5A /* MoonUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F919DDE2AF00553C5A /* MoonUtils.swift */; };
33 | 11C516FB19DDE2AF00553C5A /* MoonUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516F919DDE2AF00553C5A /* MoonUtils.swift */; };
34 | 11C516FD19DDE2BF00553C5A /* PositionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516FC19DDE2BF00553C5A /* PositionUtils.swift */; };
35 | 11C516FE19DDE2BF00553C5A /* PositionUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516FC19DDE2BF00553C5A /* PositionUtils.swift */; };
36 | 11C5170019DDE2CD00553C5A /* SunUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516FF19DDE2CD00553C5A /* SunUtils.swift */; };
37 | 11C5170119DDE2CD00553C5A /* SunUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C516FF19DDE2CD00553C5A /* SunUtils.swift */; };
38 | 11C5170319DDE2D800553C5A /* TimeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C5170219DDE2D800553C5A /* TimeUtils.swift */; };
39 | 11C5170419DDE2D800553C5A /* TimeUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C5170219DDE2D800553C5A /* TimeUtils.swift */; };
40 | 11DEE58B22DE54CD0024D20D /* MoonTimes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11DEE58A22DE54CD0024D20D /* MoonTimes.swift */; };
41 | 11DEE58C22DE54D60024D20D /* MoonTimes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11DEE58A22DE54CD0024D20D /* MoonTimes.swift */; };
42 | /* End PBXBuildFile section */
43 |
44 | /* Begin PBXContainerItemProxy section */
45 | 11C516CE19DDDD9200553C5A /* PBXContainerItemProxy */ = {
46 | isa = PBXContainerItemProxy;
47 | containerPortal = 11C516B019DDDD9200553C5A /* Project object */;
48 | proxyType = 1;
49 | remoteGlobalIDString = 11C516B719DDDD9200553C5A;
50 | remoteInfo = "suncalc-example";
51 | };
52 | /* End PBXContainerItemProxy section */
53 |
54 | /* Begin PBXFileReference section */
55 | 11C516B819DDDD9200553C5A /* suncalc-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "suncalc-example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
56 | 11C516BC19DDDD9200553C5A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
57 | 11C516BD19DDDD9200553C5A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
58 | 11C516BF19DDDD9200553C5A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
59 | 11C516C219DDDD9200553C5A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
60 | 11C516C419DDDD9200553C5A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
61 | 11C516C719DDDD9200553C5A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
62 | 11C516CD19DDDD9200553C5A /* suncalc-exampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "suncalc-exampleTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
63 | 11C516D219DDDD9200553C5A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
64 | 11C516D319DDDD9200553C5A /* suncalc_exampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = suncalc_exampleTests.swift; sourceTree = ""; };
65 | 11C516DF19DDDE6D00553C5A /* suncalc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = suncalc.swift; sourceTree = ""; };
66 | 11C516E419DDE23600553C5A /* SunPosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SunPosition.swift; sourceTree = ""; };
67 | 11C516E719DDE24500553C5A /* MoonPosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoonPosition.swift; sourceTree = ""; };
68 | 11C516EA19DDE25600553C5A /* MoonIllumination.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoonIllumination.swift; sourceTree = ""; };
69 | 11C516ED19DDE26B00553C5A /* GeocentricCoordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeocentricCoordinates.swift; sourceTree = ""; };
70 | 11C516F019DDE27C00553C5A /* EquatorialCoordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EquatorialCoordinates.swift; sourceTree = ""; };
71 | 11C516F319DDE28D00553C5A /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; };
72 | 11C516F619DDE2A300553C5A /* DateUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateUtils.swift; sourceTree = ""; };
73 | 11C516F919DDE2AF00553C5A /* MoonUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoonUtils.swift; sourceTree = ""; };
74 | 11C516FC19DDE2BF00553C5A /* PositionUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PositionUtils.swift; sourceTree = ""; };
75 | 11C516FF19DDE2CD00553C5A /* SunUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SunUtils.swift; sourceTree = ""; };
76 | 11C5170219DDE2D800553C5A /* TimeUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TimeUtils.swift; sourceTree = ""; };
77 | 11C5170519DE0D1C00553C5A /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; };
78 | 11C5170619DE0D2500553C5A /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; };
79 | 11DEE58A22DE54CD0024D20D /* MoonTimes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoonTimes.swift; sourceTree = ""; };
80 | /* End PBXFileReference section */
81 |
82 | /* Begin PBXFrameworksBuildPhase section */
83 | 11C516B519DDDD9200553C5A /* Frameworks */ = {
84 | isa = PBXFrameworksBuildPhase;
85 | buildActionMask = 2147483647;
86 | files = (
87 | );
88 | runOnlyForDeploymentPostprocessing = 0;
89 | };
90 | 11C516CA19DDDD9200553C5A /* Frameworks */ = {
91 | isa = PBXFrameworksBuildPhase;
92 | buildActionMask = 2147483647;
93 | files = (
94 | );
95 | runOnlyForDeploymentPostprocessing = 0;
96 | };
97 | /* End PBXFrameworksBuildPhase section */
98 |
99 | /* Begin PBXGroup section */
100 | 11C516AF19DDDD9200553C5A = {
101 | isa = PBXGroup;
102 | children = (
103 | 11C5170519DE0D1C00553C5A /* LICENSE */,
104 | 11C5170619DE0D2500553C5A /* README.md */,
105 | 11C516DD19DDDE6D00553C5A /* suncalc */,
106 | 11C516BA19DDDD9200553C5A /* suncalc-example */,
107 | 11C516D019DDDD9200553C5A /* suncalc-exampleTests */,
108 | 11C516B919DDDD9200553C5A /* Products */,
109 | );
110 | sourceTree = "";
111 | };
112 | 11C516B919DDDD9200553C5A /* Products */ = {
113 | isa = PBXGroup;
114 | children = (
115 | 11C516B819DDDD9200553C5A /* suncalc-example.app */,
116 | 11C516CD19DDDD9200553C5A /* suncalc-exampleTests.xctest */,
117 | );
118 | name = Products;
119 | sourceTree = "";
120 | };
121 | 11C516BA19DDDD9200553C5A /* suncalc-example */ = {
122 | isa = PBXGroup;
123 | children = (
124 | 11C516BD19DDDD9200553C5A /* AppDelegate.swift */,
125 | 11C516BF19DDDD9200553C5A /* ViewController.swift */,
126 | 11C516C119DDDD9200553C5A /* Main.storyboard */,
127 | 11C516C419DDDD9200553C5A /* Images.xcassets */,
128 | 11C516C619DDDD9200553C5A /* LaunchScreen.xib */,
129 | 11C516BB19DDDD9200553C5A /* Supporting Files */,
130 | );
131 | path = "suncalc-example";
132 | sourceTree = "";
133 | };
134 | 11C516BB19DDDD9200553C5A /* Supporting Files */ = {
135 | isa = PBXGroup;
136 | children = (
137 | 11C516BC19DDDD9200553C5A /* Info.plist */,
138 | );
139 | name = "Supporting Files";
140 | sourceTree = "";
141 | };
142 | 11C516D019DDDD9200553C5A /* suncalc-exampleTests */ = {
143 | isa = PBXGroup;
144 | children = (
145 | 11C516D319DDDD9200553C5A /* suncalc_exampleTests.swift */,
146 | 11C516D119DDDD9200553C5A /* Supporting Files */,
147 | );
148 | path = "suncalc-exampleTests";
149 | sourceTree = "";
150 | };
151 | 11C516D119DDDD9200553C5A /* Supporting Files */ = {
152 | isa = PBXGroup;
153 | children = (
154 | 11C516D219DDDD9200553C5A /* Info.plist */,
155 | );
156 | name = "Supporting Files";
157 | sourceTree = "";
158 | };
159 | 11C516DD19DDDE6D00553C5A /* suncalc */ = {
160 | isa = PBXGroup;
161 | children = (
162 | 11C516DE19DDDE6D00553C5A /* models */,
163 | 11C516DF19DDDE6D00553C5A /* suncalc.swift */,
164 | 11C516E019DDDE6D00553C5A /* utils */,
165 | );
166 | name = suncalc;
167 | path = ../suncalc;
168 | sourceTree = "";
169 | };
170 | 11C516DE19DDDE6D00553C5A /* models */ = {
171 | isa = PBXGroup;
172 | children = (
173 | 11C516E419DDE23600553C5A /* SunPosition.swift */,
174 | 11C516E719DDE24500553C5A /* MoonPosition.swift */,
175 | 11C516EA19DDE25600553C5A /* MoonIllumination.swift */,
176 | 11C516ED19DDE26B00553C5A /* GeocentricCoordinates.swift */,
177 | 11C516F019DDE27C00553C5A /* EquatorialCoordinates.swift */,
178 | 11DEE58A22DE54CD0024D20D /* MoonTimes.swift */,
179 | );
180 | path = models;
181 | sourceTree = "";
182 | };
183 | 11C516E019DDDE6D00553C5A /* utils */ = {
184 | isa = PBXGroup;
185 | children = (
186 | 11C516F319DDE28D00553C5A /* Constants.swift */,
187 | 11C516F619DDE2A300553C5A /* DateUtils.swift */,
188 | 11C516F919DDE2AF00553C5A /* MoonUtils.swift */,
189 | 11C516FC19DDE2BF00553C5A /* PositionUtils.swift */,
190 | 11C516FF19DDE2CD00553C5A /* SunUtils.swift */,
191 | 11C5170219DDE2D800553C5A /* TimeUtils.swift */,
192 | );
193 | path = utils;
194 | sourceTree = "";
195 | };
196 | /* End PBXGroup section */
197 |
198 | /* Begin PBXNativeTarget section */
199 | 11C516B719DDDD9200553C5A /* suncalc-example */ = {
200 | isa = PBXNativeTarget;
201 | buildConfigurationList = 11C516D719DDDD9200553C5A /* Build configuration list for PBXNativeTarget "suncalc-example" */;
202 | buildPhases = (
203 | 11C516B419DDDD9200553C5A /* Sources */,
204 | 11C516B519DDDD9200553C5A /* Frameworks */,
205 | 11C516B619DDDD9200553C5A /* Resources */,
206 | );
207 | buildRules = (
208 | );
209 | dependencies = (
210 | );
211 | name = "suncalc-example";
212 | productName = "suncalc-example";
213 | productReference = 11C516B819DDDD9200553C5A /* suncalc-example.app */;
214 | productType = "com.apple.product-type.application";
215 | };
216 | 11C516CC19DDDD9200553C5A /* suncalc-exampleTests */ = {
217 | isa = PBXNativeTarget;
218 | buildConfigurationList = 11C516DA19DDDD9200553C5A /* Build configuration list for PBXNativeTarget "suncalc-exampleTests" */;
219 | buildPhases = (
220 | 11C516C919DDDD9200553C5A /* Sources */,
221 | 11C516CA19DDDD9200553C5A /* Frameworks */,
222 | 11C516CB19DDDD9200553C5A /* Resources */,
223 | );
224 | buildRules = (
225 | );
226 | dependencies = (
227 | 11C516CF19DDDD9200553C5A /* PBXTargetDependency */,
228 | );
229 | name = "suncalc-exampleTests";
230 | productName = "suncalc-exampleTests";
231 | productReference = 11C516CD19DDDD9200553C5A /* suncalc-exampleTests.xctest */;
232 | productType = "com.apple.product-type.bundle.unit-test";
233 | };
234 | /* End PBXNativeTarget section */
235 |
236 | /* Begin PBXProject section */
237 | 11C516B019DDDD9200553C5A /* Project object */ = {
238 | isa = PBXProject;
239 | attributes = {
240 | LastSwiftMigration = 0710;
241 | LastSwiftUpdateCheck = 0710;
242 | LastUpgradeCheck = 1010;
243 | ORGANIZATIONNAME = "Chimani, LLC";
244 | TargetAttributes = {
245 | 11C516B719DDDD9200553C5A = {
246 | CreatedOnToolsVersion = 6.0.1;
247 | };
248 | 11C516CC19DDDD9200553C5A = {
249 | CreatedOnToolsVersion = 6.0.1;
250 | TestTargetID = 11C516B719DDDD9200553C5A;
251 | };
252 | };
253 | };
254 | buildConfigurationList = 11C516B319DDDD9200553C5A /* Build configuration list for PBXProject "suncalc-example" */;
255 | compatibilityVersion = "Xcode 3.2";
256 | developmentRegion = English;
257 | hasScannedForEncodings = 0;
258 | knownRegions = (
259 | en,
260 | Base,
261 | );
262 | mainGroup = 11C516AF19DDDD9200553C5A;
263 | productRefGroup = 11C516B919DDDD9200553C5A /* Products */;
264 | projectDirPath = "";
265 | projectRoot = "";
266 | targets = (
267 | 11C516B719DDDD9200553C5A /* suncalc-example */,
268 | 11C516CC19DDDD9200553C5A /* suncalc-exampleTests */,
269 | );
270 | };
271 | /* End PBXProject section */
272 |
273 | /* Begin PBXResourcesBuildPhase section */
274 | 11C516B619DDDD9200553C5A /* Resources */ = {
275 | isa = PBXResourcesBuildPhase;
276 | buildActionMask = 2147483647;
277 | files = (
278 | 11C516C319DDDD9200553C5A /* Main.storyboard in Resources */,
279 | 11C516C819DDDD9200553C5A /* LaunchScreen.xib in Resources */,
280 | 11C516C519DDDD9200553C5A /* Images.xcassets in Resources */,
281 | );
282 | runOnlyForDeploymentPostprocessing = 0;
283 | };
284 | 11C516CB19DDDD9200553C5A /* Resources */ = {
285 | isa = PBXResourcesBuildPhase;
286 | buildActionMask = 2147483647;
287 | files = (
288 | );
289 | runOnlyForDeploymentPostprocessing = 0;
290 | };
291 | /* End PBXResourcesBuildPhase section */
292 |
293 | /* Begin PBXSourcesBuildPhase section */
294 | 11C516B419DDDD9200553C5A /* Sources */ = {
295 | isa = PBXSourcesBuildPhase;
296 | buildActionMask = 2147483647;
297 | files = (
298 | 11C516F119DDE27C00553C5A /* EquatorialCoordinates.swift in Sources */,
299 | 11C516C019DDDD9200553C5A /* ViewController.swift in Sources */,
300 | 11C516EB19DDE25600553C5A /* MoonIllumination.swift in Sources */,
301 | 11C516FA19DDE2AF00553C5A /* MoonUtils.swift in Sources */,
302 | 11DEE58B22DE54CD0024D20D /* MoonTimes.swift in Sources */,
303 | 11C516E119DDDE6D00553C5A /* suncalc.swift in Sources */,
304 | 11C516EE19DDE26B00553C5A /* GeocentricCoordinates.swift in Sources */,
305 | 11C5170319DDE2D800553C5A /* TimeUtils.swift in Sources */,
306 | 11C516E819DDE24500553C5A /* MoonPosition.swift in Sources */,
307 | 11C5170019DDE2CD00553C5A /* SunUtils.swift in Sources */,
308 | 11C516BE19DDDD9200553C5A /* AppDelegate.swift in Sources */,
309 | 11C516FD19DDE2BF00553C5A /* PositionUtils.swift in Sources */,
310 | 11C516F719DDE2A300553C5A /* DateUtils.swift in Sources */,
311 | 11C516E519DDE23600553C5A /* SunPosition.swift in Sources */,
312 | 11C516F419DDE28D00553C5A /* Constants.swift in Sources */,
313 | );
314 | runOnlyForDeploymentPostprocessing = 0;
315 | };
316 | 11C516C919DDDD9200553C5A /* Sources */ = {
317 | isa = PBXSourcesBuildPhase;
318 | buildActionMask = 2147483647;
319 | files = (
320 | 11C516EF19DDE26B00553C5A /* GeocentricCoordinates.swift in Sources */,
321 | 11C516F219DDE27C00553C5A /* EquatorialCoordinates.swift in Sources */,
322 | 11C516E619DDE23600553C5A /* SunPosition.swift in Sources */,
323 | 11C516D419DDDD9200553C5A /* suncalc_exampleTests.swift in Sources */,
324 | 11C516F819DDE2A300553C5A /* DateUtils.swift in Sources */,
325 | 11C5170419DDE2D800553C5A /* TimeUtils.swift in Sources */,
326 | 11C516E219DDDE6D00553C5A /* suncalc.swift in Sources */,
327 | 11DEE58C22DE54D60024D20D /* MoonTimes.swift in Sources */,
328 | 11C516FE19DDE2BF00553C5A /* PositionUtils.swift in Sources */,
329 | 11C516E919DDE24500553C5A /* MoonPosition.swift in Sources */,
330 | 11C5170119DDE2CD00553C5A /* SunUtils.swift in Sources */,
331 | 11C516EC19DDE25600553C5A /* MoonIllumination.swift in Sources */,
332 | 11C516FB19DDE2AF00553C5A /* MoonUtils.swift in Sources */,
333 | 11C516F519DDE28D00553C5A /* Constants.swift in Sources */,
334 | );
335 | runOnlyForDeploymentPostprocessing = 0;
336 | };
337 | /* End PBXSourcesBuildPhase section */
338 |
339 | /* Begin PBXTargetDependency section */
340 | 11C516CF19DDDD9200553C5A /* PBXTargetDependency */ = {
341 | isa = PBXTargetDependency;
342 | target = 11C516B719DDDD9200553C5A /* suncalc-example */;
343 | targetProxy = 11C516CE19DDDD9200553C5A /* PBXContainerItemProxy */;
344 | };
345 | /* End PBXTargetDependency section */
346 |
347 | /* Begin PBXVariantGroup section */
348 | 11C516C119DDDD9200553C5A /* Main.storyboard */ = {
349 | isa = PBXVariantGroup;
350 | children = (
351 | 11C516C219DDDD9200553C5A /* Base */,
352 | );
353 | name = Main.storyboard;
354 | sourceTree = "";
355 | };
356 | 11C516C619DDDD9200553C5A /* LaunchScreen.xib */ = {
357 | isa = PBXVariantGroup;
358 | children = (
359 | 11C516C719DDDD9200553C5A /* Base */,
360 | );
361 | name = LaunchScreen.xib;
362 | sourceTree = "";
363 | };
364 | /* End PBXVariantGroup section */
365 |
366 | /* Begin XCBuildConfiguration section */
367 | 11C516D519DDDD9200553C5A /* Debug */ = {
368 | isa = XCBuildConfiguration;
369 | buildSettings = {
370 | ALWAYS_SEARCH_USER_PATHS = NO;
371 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
372 | CLANG_CXX_LIBRARY = "libc++";
373 | CLANG_ENABLE_MODULES = YES;
374 | CLANG_ENABLE_OBJC_ARC = YES;
375 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
376 | CLANG_WARN_BOOL_CONVERSION = YES;
377 | CLANG_WARN_COMMA = YES;
378 | CLANG_WARN_CONSTANT_CONVERSION = YES;
379 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
380 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
381 | CLANG_WARN_EMPTY_BODY = YES;
382 | CLANG_WARN_ENUM_CONVERSION = YES;
383 | CLANG_WARN_INFINITE_RECURSION = YES;
384 | CLANG_WARN_INT_CONVERSION = YES;
385 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
386 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
387 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
388 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
389 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
390 | CLANG_WARN_STRICT_PROTOTYPES = YES;
391 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
392 | CLANG_WARN_UNREACHABLE_CODE = YES;
393 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
394 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
395 | COPY_PHASE_STRIP = NO;
396 | ENABLE_STRICT_OBJC_MSGSEND = YES;
397 | ENABLE_TESTABILITY = YES;
398 | GCC_C_LANGUAGE_STANDARD = gnu99;
399 | GCC_DYNAMIC_NO_PIC = NO;
400 | GCC_NO_COMMON_BLOCKS = YES;
401 | GCC_OPTIMIZATION_LEVEL = 0;
402 | GCC_PREPROCESSOR_DEFINITIONS = (
403 | "DEBUG=1",
404 | "$(inherited)",
405 | );
406 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
407 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
408 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
409 | GCC_WARN_UNDECLARED_SELECTOR = YES;
410 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
411 | GCC_WARN_UNUSED_FUNCTION = YES;
412 | GCC_WARN_UNUSED_VARIABLE = YES;
413 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
414 | MTL_ENABLE_DEBUG_INFO = YES;
415 | ONLY_ACTIVE_ARCH = YES;
416 | SDKROOT = iphoneos;
417 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
418 | TARGETED_DEVICE_FAMILY = "1,2";
419 | };
420 | name = Debug;
421 | };
422 | 11C516D619DDDD9200553C5A /* Release */ = {
423 | isa = XCBuildConfiguration;
424 | buildSettings = {
425 | ALWAYS_SEARCH_USER_PATHS = NO;
426 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
427 | CLANG_CXX_LIBRARY = "libc++";
428 | CLANG_ENABLE_MODULES = YES;
429 | CLANG_ENABLE_OBJC_ARC = YES;
430 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
431 | CLANG_WARN_BOOL_CONVERSION = YES;
432 | CLANG_WARN_COMMA = YES;
433 | CLANG_WARN_CONSTANT_CONVERSION = YES;
434 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
435 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
436 | CLANG_WARN_EMPTY_BODY = YES;
437 | CLANG_WARN_ENUM_CONVERSION = YES;
438 | CLANG_WARN_INFINITE_RECURSION = YES;
439 | CLANG_WARN_INT_CONVERSION = YES;
440 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
441 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
442 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
443 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
444 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
445 | CLANG_WARN_STRICT_PROTOTYPES = YES;
446 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
447 | CLANG_WARN_UNREACHABLE_CODE = YES;
448 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
449 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
450 | COPY_PHASE_STRIP = YES;
451 | ENABLE_NS_ASSERTIONS = NO;
452 | ENABLE_STRICT_OBJC_MSGSEND = YES;
453 | GCC_C_LANGUAGE_STANDARD = gnu99;
454 | GCC_NO_COMMON_BLOCKS = YES;
455 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
456 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
457 | GCC_WARN_UNDECLARED_SELECTOR = YES;
458 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
459 | GCC_WARN_UNUSED_FUNCTION = YES;
460 | GCC_WARN_UNUSED_VARIABLE = YES;
461 | IPHONEOS_DEPLOYMENT_TARGET = 8.0;
462 | MTL_ENABLE_DEBUG_INFO = NO;
463 | SDKROOT = iphoneos;
464 | SWIFT_COMPILATION_MODE = wholemodule;
465 | TARGETED_DEVICE_FAMILY = "1,2";
466 | VALIDATE_PRODUCT = YES;
467 | };
468 | name = Release;
469 | };
470 | 11C516D819DDDD9200553C5A /* Debug */ = {
471 | isa = XCBuildConfiguration;
472 | buildSettings = {
473 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
474 | DEVELOPMENT_TEAM = "";
475 | INFOPLIST_FILE = "suncalc-example/Info.plist";
476 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
477 | PRODUCT_BUNDLE_IDENTIFIER = "com.chimani.$(PRODUCT_NAME:rfc1034identifier)";
478 | PRODUCT_NAME = "$(TARGET_NAME)";
479 | SWIFT_VERSION = 4.2;
480 | };
481 | name = Debug;
482 | };
483 | 11C516D919DDDD9200553C5A /* Release */ = {
484 | isa = XCBuildConfiguration;
485 | buildSettings = {
486 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
487 | DEVELOPMENT_TEAM = "";
488 | INFOPLIST_FILE = "suncalc-example/Info.plist";
489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
490 | PRODUCT_BUNDLE_IDENTIFIER = "com.chimani.$(PRODUCT_NAME:rfc1034identifier)";
491 | PRODUCT_NAME = "$(TARGET_NAME)";
492 | SWIFT_VERSION = 4.2;
493 | };
494 | name = Release;
495 | };
496 | 11C516DB19DDDD9200553C5A /* Debug */ = {
497 | isa = XCBuildConfiguration;
498 | buildSettings = {
499 | BUNDLE_LOADER = "$(TEST_HOST)";
500 | FRAMEWORK_SEARCH_PATHS = "";
501 | GCC_PREPROCESSOR_DEFINITIONS = (
502 | "DEBUG=1",
503 | "$(inherited)",
504 | );
505 | INFOPLIST_FILE = "suncalc-exampleTests/Info.plist";
506 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
507 | PRODUCT_BUNDLE_IDENTIFIER = "com.chimani.$(PRODUCT_NAME:rfc1034identifier)";
508 | PRODUCT_NAME = "$(TARGET_NAME)";
509 | SWIFT_VERSION = 4.2;
510 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/suncalc-example.app/suncalc-example";
511 | };
512 | name = Debug;
513 | };
514 | 11C516DC19DDDD9200553C5A /* Release */ = {
515 | isa = XCBuildConfiguration;
516 | buildSettings = {
517 | BUNDLE_LOADER = "$(TEST_HOST)";
518 | FRAMEWORK_SEARCH_PATHS = "";
519 | INFOPLIST_FILE = "suncalc-exampleTests/Info.plist";
520 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
521 | PRODUCT_BUNDLE_IDENTIFIER = "com.chimani.$(PRODUCT_NAME:rfc1034identifier)";
522 | PRODUCT_NAME = "$(TARGET_NAME)";
523 | SWIFT_VERSION = 4.2;
524 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/suncalc-example.app/suncalc-example";
525 | };
526 | name = Release;
527 | };
528 | /* End XCBuildConfiguration section */
529 |
530 | /* Begin XCConfigurationList section */
531 | 11C516B319DDDD9200553C5A /* Build configuration list for PBXProject "suncalc-example" */ = {
532 | isa = XCConfigurationList;
533 | buildConfigurations = (
534 | 11C516D519DDDD9200553C5A /* Debug */,
535 | 11C516D619DDDD9200553C5A /* Release */,
536 | );
537 | defaultConfigurationIsVisible = 0;
538 | defaultConfigurationName = Release;
539 | };
540 | 11C516D719DDDD9200553C5A /* Build configuration list for PBXNativeTarget "suncalc-example" */ = {
541 | isa = XCConfigurationList;
542 | buildConfigurations = (
543 | 11C516D819DDDD9200553C5A /* Debug */,
544 | 11C516D919DDDD9200553C5A /* Release */,
545 | );
546 | defaultConfigurationIsVisible = 0;
547 | defaultConfigurationName = Release;
548 | };
549 | 11C516DA19DDDD9200553C5A /* Build configuration list for PBXNativeTarget "suncalc-exampleTests" */ = {
550 | isa = XCConfigurationList;
551 | buildConfigurations = (
552 | 11C516DB19DDDD9200553C5A /* Debug */,
553 | 11C516DC19DDDD9200553C5A /* Release */,
554 | );
555 | defaultConfigurationIsVisible = 0;
556 | defaultConfigurationName = Release;
557 | };
558 | /* End XCConfigurationList section */
559 | };
560 | rootObject = 11C516B019DDDD9200553C5A /* Project object */;
561 | }
562 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import UIKit
9 |
10 | @UIApplicationMain
11 | class AppDelegate: UIResponder, UIApplicationDelegate {
12 |
13 | var window: UIWindow?
14 |
15 |
16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17 | // Override point for customization after application launch.
18 | return true
19 | }
20 |
21 | func applicationWillResignActive(_ application: UIApplication) {
22 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
23 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
24 | }
25 |
26 | func applicationDidEnterBackground(_ application: UIApplication) {
27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
29 | }
30 |
31 | func applicationWillEnterForeground(_ application: UIApplication) {
32 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
33 | }
34 |
35 | func applicationDidBecomeActive(_ application: UIApplication) {
36 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
37 | }
38 |
39 | func applicationWillTerminate(_ application: UIApplication) {
40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
41 | }
42 |
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
29 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 0.2
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 2
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-example/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import UIKit
9 |
10 | class ViewController: UIViewController {
11 |
12 | @IBOutlet weak var timeLabel: UILabel!
13 |
14 | override func viewDidLoad() {
15 | super.viewDidLoad()
16 | let date:Date = Date()
17 | let sunCalc:SunCalc = SunCalc.getTimes(date: date, latitude: 51.5, longitude: -0.1)
18 |
19 | let formatter:DateFormatter = DateFormatter()
20 | formatter.dateFormat = "HH:mm"
21 | formatter.timeZone = TimeZone(abbreviation: "GMT")
22 | let sunriseString:String = formatter.string(from: sunCalc.sunrise)
23 | timeLabel.text = sunriseString
24 | }
25 |
26 | override func didReceiveMemoryWarning() {
27 | super.didReceiveMemoryWarning()
28 | // Dispose of any resources that can be recreated.
29 | }
30 |
31 |
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-exampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/suncalc-example/suncalc-exampleTests/suncalc_exampleTests.swift:
--------------------------------------------------------------------------------
1 | //
2 | // suncalc_exampleTests.swift
3 | // suncalc-exampleTests
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import UIKit
9 | import XCTest
10 |
11 | let NEARNESS = 1e-9
12 |
13 | class suncalc_exampleTests: XCTestCase {
14 | var date:Date = Date()
15 | var LAT:Double = 50.5
16 | var LNG:Double = 30.5
17 |
18 | override func setUp() {
19 | super.setUp()
20 | var calendar:Calendar = Calendar(identifier: Calendar.Identifier.gregorian)
21 | calendar.timeZone = TimeZone(abbreviation: "GMT")!
22 | let components:DateComponents = DateComponents(year: 2013, month: 3, day: 5)
23 |
24 | self.date = calendar.date(from: components)!
25 | }
26 |
27 | override func tearDown() {
28 | super.tearDown()
29 | }
30 |
31 | func test_sun_getTimes() {
32 | let sunCalc:SunCalc = SunCalc.getTimes(date: date, latitude: LAT, longitude: LNG)
33 |
34 | let formatter:DateFormatter = DateFormatter()
35 | formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"
36 | formatter.timeZone = TimeZone(abbreviation: "GMT")
37 |
38 | XCTAssertEqual(formatter.string(from: sunCalc.solarNoon), "2013-03-05T10:10:57Z")
39 | XCTAssertEqual(formatter.string(from: sunCalc.nadir), "2013-03-04T22:10:57Z")
40 | XCTAssertEqual(formatter.string(from: sunCalc.sunrise), "2013-03-05T04:34:57Z")
41 | XCTAssertEqual(formatter.string(from: sunCalc.sunset), "2013-03-05T15:46:56Z")
42 | XCTAssertEqual(formatter.string(from: sunCalc.sunriseEnd), "2013-03-05T04:38:19Z")
43 | XCTAssertEqual(formatter.string(from: sunCalc.sunsetStart), "2013-03-05T15:43:34Z")
44 | XCTAssertEqual(formatter.string(from: sunCalc.dawn), "2013-03-05T04:02:17Z")
45 | XCTAssertEqual(formatter.string(from: sunCalc.dusk), "2013-03-05T16:19:36Z")
46 | XCTAssertEqual(formatter.string(from: sunCalc.nauticalDawn), "2013-03-05T03:24:31Z")
47 | XCTAssertEqual(formatter.string(from: sunCalc.nauticalDusk), "2013-03-05T16:57:22Z")
48 | XCTAssertEqual(formatter.string(from: sunCalc.nightEnd), "2013-03-05T02:46:17Z")
49 | XCTAssertEqual(formatter.string(from: sunCalc.night), "2013-03-05T17:35:36Z")
50 | XCTAssertEqual(formatter.string(from: sunCalc.goldenHourEnd), "2013-03-05T05:19:01Z")
51 | XCTAssertEqual(formatter.string(from: sunCalc.goldenHour), "2013-03-05T15:02:52Z")
52 | }
53 |
54 | func test_sun_getPosition() {
55 | let sunPos:SunPosition = SunCalc.getSunPosition(timeAndDate: date, latitude: LAT, longitude: LNG)
56 | XCTAssertEqual(sunPos.azimuth, -2.5003175907168385, accuracy: NEARNESS)
57 | XCTAssertEqual(sunPos.altitude, -0.7000406838781611, accuracy: NEARNESS)
58 | }
59 |
60 | func test_getMoonPosition() {
61 | let moonPos:MoonPosition = SunCalc.getMoonPosition(timeAndDate: date, latitude: LAT, longitude: LNG)
62 | XCTAssertEqual(moonPos.azimuth, -0.9783999522438226, accuracy: NEARNESS)
63 | XCTAssertEqual(moonPos.altitude, 0.006969727754891917, accuracy: NEARNESS)
64 | XCTAssertEqual(moonPos.distance, 364121.37256256294, accuracy: NEARNESS)
65 | }
66 |
67 | func test_getMoonIllumination() {
68 | let moonIllum:MoonIllumination = SunCalc.getMoonIllumination(timeAndDate: date)
69 | XCTAssertEqual(moonIllum.fraction, 0.4848068202456373, accuracy: NEARNESS)
70 | XCTAssertEqual(moonIllum.phase, 0.7548368838538762, accuracy: NEARNESS)
71 | XCTAssertEqual(moonIllum.angle, 1.6732942678578346, accuracy: NEARNESS)
72 | }
73 |
74 | func test_getMoonTimes() {
75 | var calendar:Calendar = Calendar(identifier: Calendar.Identifier.gregorian)
76 | calendar.timeZone = TimeZone(abbreviation: "GMT")!
77 | let components:DateComponents = DateComponents(year: 2013, month: 3, day: 4, hour: 0, minute: 0, second: 0)
78 |
79 | let moonTimes:MoonTimes = SunCalc.getMoonTimes(date: calendar.date(from: components)!, latitude: LAT, longitude: LNG)
80 | let formatter:DateFormatter = DateFormatter()
81 | formatter.dateFormat = "E, d MMM yyyy HH:mm:ss zzz"
82 | formatter.timeZone = TimeZone(abbreviation: "GMT")
83 | let rise:Date = formatter.date(from: "Mon, 04 Mar 2013 23:54:29 GMT")!
84 | let set:Date = formatter.date(from: "Mon, 04 Mar 2013 07:47:58 GMT")!
85 | let moonRise:Date = moonTimes.rise ?? Date()
86 | let moonSet:Date = moonTimes.set ?? Date()
87 | let slop:Double = 20 * 60 // 20 minutes
88 |
89 | XCTAssertTrue((moonRise >= rise.addingTimeInterval(-1 * slop)) && (moonRise <= rise.addingTimeInterval(slop)))
90 | //XCTAssertEqual(formatter.string(from: moonTimes.rise ?? Date()), "Mon, 04 Mar 2013 23:54:29 GMT")
91 | XCTAssertTrue((moonSet >= set.addingTimeInterval(-1 * slop)) && (moonSet <= set.addingTimeInterval(slop)))
92 | //XCTAssertEqual(formatter.string(from: moonTimes.set ?? Date()), "Mon, 04 Mar 2013 07:47:58 GMT")
93 | }
94 |
95 | func test_README_example() {
96 | let date:Date = Date()
97 | let sunCalc:SunCalc = SunCalc.getTimes(date: date, latitude: 51.5, longitude: -0.1)
98 |
99 | let formatter:DateFormatter = DateFormatter()
100 | formatter.dateFormat = "HH:mm"
101 | formatter.timeZone = TimeZone(abbreviation: "GMT")
102 | let sunriseString:String = formatter.string(from: sunCalc.sunrise)
103 | print("sunrise is at \(sunriseString)")
104 |
105 | let sunPos:SunPosition = SunCalc.getSunPosition(timeAndDate: date, latitude: 51.5, longitude: -0.1)
106 |
107 | let sunriseAzimuth:Double = sunPos.azimuth * 180 / Constants.PI()
108 | print("sunrise azimuth: \(sunriseAzimuth)")
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/suncalc-swift.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = "suncalc-swift"
3 | s.version = "0.2.0"
4 | s.summary = "This is a swift 2 port for iOS of https://github.com/mourner/suncalc"
5 | s.homepage = "https://github.com/shanus/suncalc-swift"
6 | s.license = { :type => "MIT" }
7 | s.authors = { "shanus" => "shaun@chimani.com" }
8 |
9 | s.requires_arc = true
10 | s.platform = :ios
11 | s.ios.deployment_target = "8.0"
12 | s.source = { :git => "https://github.com/shanus/suncalc-swift.git", :tag => "0.2.0"}
13 | s.source_files = "suncalc/**/*.swift"
14 | end
--------------------------------------------------------------------------------
/suncalc/models/EquatorialCoordinates.swift:
--------------------------------------------------------------------------------
1 | //
2 | // EquatorialCoordinates.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class EquatorialCoordinates {
11 | var rightAscension:Double
12 | var declination:Double
13 |
14 | init(rightAscension:Double, declination:Double) {
15 | self.rightAscension = rightAscension
16 | self.declination = declination
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/suncalc/models/GeocentricCoordinates.swift:
--------------------------------------------------------------------------------
1 | //
2 | // GeocentricCoordinates.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class GeocentricCoordinates {
11 | var rightAscension:Double;
12 | var declination:Double;
13 | var distance:Double;
14 |
15 | init(rightAscension:Double, declination:Double, distance:Double) {
16 | self.rightAscension = rightAscension
17 | self.declination = declination
18 | self.distance = distance
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/suncalc/models/MoonIllumination.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MoonIllumination.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class MoonIllumination {
11 | var fraction:Double
12 | var phase:Double
13 | var angle:Double
14 |
15 | init(fraction:Double, phase:Double, angle:Double) {
16 | self.fraction = fraction
17 | self.phase = phase
18 | self.angle = angle
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/suncalc/models/MoonPosition.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MoonPosition.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class MoonPosition {
11 | var azimuth:Double
12 | var altitude:Double
13 | var distance:Double
14 |
15 | init(azimuth:Double, altitude:Double, distance:Double) {
16 | self.azimuth = azimuth
17 | self.altitude = altitude
18 | self.distance = distance
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/suncalc/models/MoonTimes.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MoonTimes.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 7/16/19.
6 | //
7 |
8 | import Foundation
9 |
10 | class MoonTimes {
11 | var rise:Date?
12 | var set:Date?
13 | var alwaysUp:Bool
14 | var alwaysDown:Bool
15 |
16 | init(rise:Date?, set:Date?, alwaysUp:Bool, alwaysDown:Bool) {
17 | self.rise = rise
18 | self.set = set
19 | self.alwaysUp = alwaysUp
20 | self.alwaysDown = alwaysDown
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/suncalc/models/SunPosition.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SunPosition.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class SunPosition {
11 | var azimuth:Double
12 | var altitude:Double
13 |
14 | init(azimuth:Double, altitude:Double) {
15 | self.azimuth = azimuth
16 | self.altitude = altitude
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/suncalc/suncalc.swift:
--------------------------------------------------------------------------------
1 | //
2 | // suncalc.swift
3 | // suncalc
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 | //
8 |
9 | import Foundation
10 |
11 | class SunCalc {
12 | let J0:Double = 0.0009
13 |
14 | var sunrise:Date
15 | var sunriseEnd:Date
16 | var goldenHourEnd:Date
17 | var solarNoon:Date
18 | var goldenHour:Date
19 | var sunsetStart:Date
20 | var sunset:Date
21 | var dusk:Date
22 | var nauticalDusk:Date
23 | var night:Date
24 | var nadir:Date
25 | var nightEnd:Date
26 | var nauticalDawn:Date
27 | var dawn:Date
28 |
29 | class func getSetJ(h:Double, phi:Double, dec:Double, lw:Double, n:Double, M:Double, L:Double) -> Double {
30 | let w:Double = TimeUtils.getHourAngle(h:h, phi: phi, d: dec)
31 | let a:Double = TimeUtils.getApproxTransit(ht: w, lw: lw, n: n)
32 |
33 | return TimeUtils.getSolarTransitJ(ds: a, M: M, L: L)
34 | }
35 |
36 | class func getTimes(date:Date, latitude:Double, longitude:Double) -> SunCalc {
37 | return SunCalc(date:date, latitude:latitude, longitude:longitude)
38 | }
39 |
40 | class func getSunPosition(timeAndDate:Date, latitude:Double, longitude:Double) -> SunPosition {
41 | let lw:Double = Constants.RAD() * -longitude
42 | let phi:Double = Constants.RAD() * latitude
43 | let d:Double = DateUtils.toDays(date: timeAndDate)
44 |
45 | let c:EquatorialCoordinates = SunUtils.getSunCoords(d: d)
46 | let H:Double = PositionUtils.getSiderealTime(d: d, lw: lw) - c.rightAscension
47 |
48 | return SunPosition(azimuth: PositionUtils.getAzimuth(h: H, phi: phi, dec: c.declination), altitude: PositionUtils.getAltitude(h: H, phi: phi, dec: c.declination))
49 | }
50 |
51 | class func getMoonPosition(timeAndDate:Date, latitude:Double, longitude:Double) -> MoonPosition {
52 | let lw:Double = Constants.RAD() * -longitude
53 | let phi:Double = Constants.RAD() * latitude
54 | let d:Double = DateUtils.toDays(date: timeAndDate)
55 |
56 | let c:GeocentricCoordinates = MoonUtils.getMoonCoords(d: d)
57 | let H:Double = PositionUtils.getSiderealTime(d: d, lw: lw) - c.rightAscension
58 | var h:Double = PositionUtils.getAltitude(h: H, phi: phi, dec: c.declination)
59 |
60 | // altitude correction for refraction
61 | h = h + Constants.RAD() * 0.017 / tan(h + Constants.RAD() * 10.26 / (h + Constants.RAD() * 5.10));
62 |
63 | return MoonPosition(azimuth: PositionUtils.getAzimuth(h: H, phi: phi, dec: c.declination), altitude: h, distance: c.distance)
64 | }
65 |
66 | class func getMoonIllumination(timeAndDate:Date) -> MoonIllumination {
67 | let d:Double = DateUtils.toDays(date: timeAndDate)
68 | let s:EquatorialCoordinates = SunUtils.getSunCoords(d: d)
69 | let m:GeocentricCoordinates = MoonUtils.getMoonCoords(d: d)
70 |
71 | let sdist:Double = 149598000; // distance from Earth to Sun in km
72 |
73 | let phi:Double = acos(sin(s.declination) * sin(m.declination) + cos(s.declination) * cos(m.declination) * cos(s.rightAscension - m.rightAscension))
74 | let inc:Double = atan2(sdist * sin(phi), m.distance - sdist * cos(phi))
75 | let angle:Double = atan2(cos(s.declination) * sin(s.rightAscension - m.rightAscension), sin(s.declination) * cos(m.declination) - cos(s.declination) * sin(m.declination) * cos(s.rightAscension - m.rightAscension))
76 |
77 | let fraction:Double = (1 + cos(inc)) / 2
78 | let phase:Double = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Constants.PI()
79 |
80 | return MoonIllumination(fraction: fraction, phase: phase, angle: angle)
81 | }
82 |
83 | class func getMoonTimes(date:Date, latitude:Double, longitude:Double) -> MoonTimes {
84 | let hc:Double = 0.133 * Constants.RAD()
85 | var h0:Double = SunCalc.getMoonPosition(timeAndDate: date, latitude: latitude, longitude: longitude).altitude - hc
86 | var h1:Double = 0, h2:Double = 0, rise:Double = 0, set:Double = 0, a:Double = 0, b:Double = 0, xe:Double = 0, ye:Double = 0, d:Double = 0, roots:Double = 0, x1:Double = 0, x2:Double = 0, dx:Double = 0
87 |
88 | // go in 2-hour chunks, each time seeing if a 3-point quadratic curve crosses zero (which means rise or set)
89 | for i in stride(from: 1, through: 24, by: 2) {
90 | h1 = SunCalc.getMoonPosition(timeAndDate: DateUtils.getHoursLater(date: date, hours: Double(i))!, latitude: latitude, longitude: longitude).altitude - hc
91 | h2 = SunCalc.getMoonPosition(timeAndDate: DateUtils.getHoursLater(date: date, hours: Double(i + 1))!, latitude: latitude, longitude: longitude).altitude - hc
92 | a = (h0 + h2) / 2 - h1
93 | b = (h2 - h0) / 2
94 | xe = -b / (2 * a)
95 | ye = (a * xe + b) * xe + h1
96 | d = b * b - 4 * a * h1
97 | roots = 0
98 |
99 | if (d >= 0) {
100 | dx = sqrt(d) / (abs(a) * 2)
101 | x1 = xe - dx
102 | x2 = xe + dx
103 | if (abs(x1) <= 1) {
104 | roots += 1
105 | }
106 | if (abs(x2) <= 1) {
107 | roots += 1
108 | }
109 | if (x1 < -1) {
110 | x1 = x2
111 | }
112 | }
113 |
114 | if (roots == 1) {
115 | if (h0 < 0) {
116 | rise = Double(i) + x1
117 | } else {
118 | set = Double(i) + x1
119 | }
120 | } else if (roots == 2) {
121 | rise = Double(i) + (ye < 0 ? x2 : x1)
122 | set = Double(i) + (ye < 0 ? x1 : x2)
123 | }
124 |
125 | if ((rise != 0) && (set != 0)) {
126 | break
127 | }
128 | h0 = h2
129 | }
130 | var result = [String:Any?]()
131 | result["alwaysUp"] = false
132 | result["alwaysDown"] = false
133 | if (rise != 0) {
134 | result["rise"] = DateUtils.getHoursLater(date: date, hours: rise)
135 | }
136 | if (set != 0) {
137 | result["set"] = DateUtils.getHoursLater(date: date, hours: set)
138 | }
139 | if ((rise == 0) && (set == 0)) {
140 | result[ye > 0 ? "alwaysUp" : "alwaysDown"] = true
141 | }
142 |
143 | return MoonTimes(rise: result["rise"] as? Date, set: result["set"] as? Date, alwaysUp: result["alwaysUp"] as! Bool, alwaysDown: result["alwaysDown"] as! Bool)
144 | }
145 |
146 |
147 | init(date:Date, latitude:Double, longitude:Double) {
148 | let lw:Double = Constants.RAD() * -longitude
149 | let phi:Double = Constants.RAD() * latitude
150 | let d:Double = DateUtils.toDays(date: date)
151 |
152 | let n:Double = TimeUtils.getJulianCycle(d: d, lw: lw)
153 | let ds:Double = TimeUtils.getApproxTransit(ht: 0, lw: lw, n: n)
154 |
155 | let M:Double = SunUtils.getSolarMeanAnomaly(d: ds)
156 | let L:Double = SunUtils.getEclipticLongitudeM(M: M)
157 | let dec:Double = PositionUtils.getDeclination(l: L, b: 0)
158 |
159 | let Jnoon:Double = TimeUtils.getSolarTransitJ(ds: ds, M: M, L: L)
160 |
161 | self.solarNoon = DateUtils.fromJulian(j: Jnoon)
162 | self.nadir = DateUtils.fromJulian(j: Jnoon - 0.5)
163 |
164 | // sun times configuration (angle, morning name, evening name)
165 | // unrolled the loop working on this data:
166 | // var times = [
167 | // [-0.83, 'sunrise', 'sunset' ],
168 | // [ -0.3, 'sunriseEnd', 'sunsetStart' ],
169 | // [ -6, 'dawn', 'dusk' ],
170 | // [ -12, 'nauticalDawn', 'nauticalDusk'],
171 | // [ -18, 'nightEnd', 'night' ],
172 | // [ 6, 'goldenHourEnd', 'goldenHour' ]
173 | // ];
174 |
175 | var h:Double = -0.83
176 | var Jset:Double = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
177 | var Jrise:Double = Jnoon - (Jset - Jnoon)
178 |
179 | self.sunrise = DateUtils.fromJulian(j: Jrise)
180 | self.sunset = DateUtils.fromJulian(j: Jset)
181 |
182 | h = -0.3;
183 | Jset = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
184 | Jrise = Jnoon - (Jset - Jnoon)
185 | self.sunriseEnd = DateUtils.fromJulian(j: Jrise)
186 | self.sunsetStart = DateUtils.fromJulian(j: Jset)
187 |
188 | h = -6;
189 | Jset = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
190 | Jrise = Jnoon - (Jset - Jnoon)
191 | self.dawn = DateUtils.fromJulian(j: Jrise)
192 | self.dusk = DateUtils.fromJulian(j: Jset)
193 |
194 | h = -12;
195 | Jset = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
196 | Jrise = Jnoon - (Jset - Jnoon)
197 | self.nauticalDawn = DateUtils.fromJulian(j: Jrise)
198 | self.nauticalDusk = DateUtils.fromJulian(j: Jset)
199 |
200 | h = -18;
201 | Jset = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
202 | Jrise = Jnoon - (Jset - Jnoon)
203 | self.nightEnd = DateUtils.fromJulian(j: Jrise)
204 | self.night = DateUtils.fromJulian(j: Jset)
205 |
206 | h = 6;
207 | Jset = SunCalc.getSetJ(h: h * Constants.RAD(), phi: phi, dec: dec, lw: lw, n: n, M: M, L: L)
208 | Jrise = Jnoon - (Jset - Jnoon)
209 | self.goldenHourEnd = DateUtils.fromJulian(j: Jrise)
210 | self.goldenHour = DateUtils.fromJulian(j: Jset)
211 |
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/suncalc/utils/Constants.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Constants.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | let π = 3.14159265358979
11 |
12 | class Constants {
13 |
14 | class func RAD() -> Double {
15 | return π / 180.0
16 | }
17 |
18 | class func E() -> Double {
19 | return Constants.RAD() * 23.4397 // obliquity of the earth
20 | }
21 |
22 | class func PI() -> Double {
23 | return π
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/suncalc/utils/DateUtils.swift:
--------------------------------------------------------------------------------
1 | //
2 | // DateUtils.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 |
11 | let DAY_SECONDS:Double = 60 * 60 * 24
12 | let J1970:Double = 2440588
13 | let J2000:Double = 2451545
14 |
15 | class DateUtils {
16 |
17 | class func toJulian(date:Date) -> Double {
18 | return Double(date.timeIntervalSince1970) / DAY_SECONDS - 0.5 + J1970
19 | }
20 |
21 | class func fromJulian(j:Double) -> Date {
22 | let timeInterval = (j + 0.5 - J1970) * DAY_SECONDS
23 | return Date(timeIntervalSince1970: timeInterval)
24 | }
25 |
26 | class func toDays(date:Date) -> Double {
27 | return DateUtils.toJulian(date: date) - J2000
28 | }
29 |
30 | class func getHoursLater(date:Date, hours:Double) -> Date? {
31 | let calendar:Calendar = Calendar(identifier: Calendar.Identifier.gregorian)
32 | return calendar.date(byAdding: .second, value: Int(hours*60*60), to: date)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/suncalc/utils/MoonUtils.swift:
--------------------------------------------------------------------------------
1 | //
2 | // MoonUtils.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class MoonUtils {
11 |
12 | class func getMoonCoords(d:Double) -> GeocentricCoordinates {
13 | // geocentric ecliptic coordinates of the moon
14 |
15 | let L:Double = Constants.RAD() * (218.316 + 13.176396 * d); // ecliptic longitude
16 | let M:Double = Constants.RAD() * (134.963 + 13.064993 * d); // mean anomaly
17 | let F:Double = Constants.RAD() * (93.272 + 13.229350 * d); // mean distance
18 |
19 | let l:Double = L + Constants.RAD() * 6.289 * sin(M); // longitude
20 | let b:Double = Constants.RAD() * 5.128 * sin(F); // latitude
21 | let dt:Double = 385001 - 20905 * cos(M); // distance to the moon in km
22 |
23 | return GeocentricCoordinates(rightAscension: PositionUtils.getRightAscension(l:l, b: b), declination: PositionUtils.getDeclination(l: l, b: b), distance: dt)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/suncalc/utils/PositionUtils.swift:
--------------------------------------------------------------------------------
1 | //
2 | // PositionUtils.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class PositionUtils {
11 |
12 | class func getRightAscension(l:Double, b:Double) -> Double {
13 | return atan2(sin(l) * cos(Constants.E()) - tan(b) * sin(Constants.E()), cos(l))
14 | }
15 |
16 | class func getDeclination(l:Double, b:Double) -> Double {
17 | return asin(sin(b) * cos(Constants.E()) + cos(b) * sin(Constants.E()) * sin(l))
18 | }
19 |
20 | class func getAzimuth(h:Double, phi:Double, dec:Double) -> Double {
21 | return atan2(sin(h), cos(h) * sin(phi) - tan(dec) * cos(phi))
22 | }
23 |
24 | class func getAltitude(h:Double, phi:Double, dec:Double) -> Double {
25 | return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(h))
26 | }
27 |
28 | class func getSiderealTime(d:Double, lw:Double) -> Double {
29 | return Constants.RAD() * (280.16 + 360.9856235 * d) - lw
30 | }
31 |
32 | class func getAstroRefraction(h:Double) -> Double {
33 | var hCalc:Double = h
34 | if (hCalc < 0) {
35 | hCalc = 0;
36 | }
37 | return 0.0002967 / tan(hCalc + 0.00312536 / (hCalc + 0.08901179));
38 | }
39 |
40 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getRightAscension instead.")
41 | class func getRightAscensionL(l:Double, b:Double) -> Double {
42 | return PositionUtils.getRightAscension(l: l, b: b)
43 | }
44 |
45 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getDeclination instead.")
46 | class func getDeclinationL(l:Double, b:Double) -> Double {
47 | return PositionUtils.getDeclination(l: l, b: b)
48 | }
49 |
50 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getAzimuth instead.")
51 | class func getAzimuthH(h:Double, phi:Double, dec:Double) -> Double {
52 | return PositionUtils.getAzimuth(h: h, phi: phi, dec: dec)
53 | }
54 |
55 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getAltitude instead.")
56 | class func getAltitudeH(h:Double, phi:Double, dec:Double) -> Double {
57 | return PositionUtils.getAltitude(h: h, phi: phi, dec: dec)
58 | }
59 |
60 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getSiderealTime instead.")
61 | class func getSiderealTimeD(d:Double, lw:Double) -> Double {
62 | return PositionUtils.getSiderealTime(d: d, lw: lw)
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/suncalc/utils/SunUtils.swift:
--------------------------------------------------------------------------------
1 | //
2 | // SunUtils.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | class SunUtils {
11 |
12 | class func getSolarMeanAnomaly(d:Double) -> Double {
13 | return Constants.RAD() * (357.5291 + 0.98560028 * d)
14 | }
15 |
16 | class func getEquationOfCenter(M:Double) -> Double {
17 | let firstFactor = 1.9148 * sin(M)
18 | let secondFactor = 0.02 * sin(2 * M)
19 | let thirdFactor = 0.0003 * sin(3 * M)
20 | return Constants.RAD() * (firstFactor + secondFactor + thirdFactor)
21 | }
22 |
23 | class func getEclipticLongitudeM(M:Double) -> Double {
24 | let C:Double = SunUtils.getEquationOfCenter(M:M)
25 | let P:Double = Constants.RAD() * 102.9372 // perihelion of the Earth
26 | return M + C + P + Constants.PI()
27 | }
28 |
29 | class func getSunCoords(d:Double) -> EquatorialCoordinates {
30 | let M:Double = SunUtils.getSolarMeanAnomaly(d:d)
31 | let L:Double = SunUtils.getEclipticLongitudeM(M:M)
32 |
33 | return EquatorialCoordinates(rightAscension: PositionUtils.getRightAscension(l: L, b: 0), declination: PositionUtils.getDeclination(l: L, b: 0))
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/suncalc/utils/TimeUtils.swift:
--------------------------------------------------------------------------------
1 | //
2 | // TimeUtils.swift
3 | // suncalc-example
4 | //
5 | // Created by Shaun Meredith on 10/2/14.
6 | //
7 |
8 | import Foundation
9 |
10 | let J0:Double = 0.0009
11 |
12 | class TimeUtils {
13 |
14 | class func getJulianCycle(d:Double, lw:Double) -> Double {
15 | return round(d - J0 - lw / (2 * Constants.PI()))
16 | }
17 |
18 | class func getApproxTransit(ht:Double, lw:Double, n:Double) -> Double {
19 | return J0 + (ht + lw) / (2 * Constants.PI()) + n
20 | }
21 |
22 | class func getSolarTransitJ(ds:Double, M:Double, L:Double) -> Double {
23 | return J2000 + ds + 0.0053 * sin(M) - 0.0069 * sin(2 * L)
24 | }
25 |
26 | class func getHourAngle(h:Double, phi:Double, d:Double) -> Double {
27 | return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d)))
28 | }
29 |
30 | class func getSetJ(h:Double, lw:Double, phi:Double, dec:Double, n:Double, M:Double, L:Double) -> Double {
31 | let w:Double = TimeUtils.getHourAngle(h: h, phi: phi, d: dec)
32 | let a:Double = TimeUtils.getApproxTransit(ht: w, lw: lw, n: n )
33 | return TimeUtils.getSolarTransitJ(ds: a, M: M, L: L)
34 | }
35 |
36 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getJulianCycle instead.")
37 | class func getJulianCycleD(d:Double, lw:Double) -> Double {
38 | return TimeUtils.getJulianCycle(d: d, lw: lw)
39 | }
40 |
41 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getApproxTransit instead.")
42 | class func getApproxTransitHt(ht:Double, lw:Double, n:Double) -> Double {
43 | return TimeUtils.getApproxTransit(ht: ht, lw: lw, n: n)
44 | }
45 |
46 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getSolarTransitJ instead.")
47 | class func getSolarTransitJDs(ds:Double, M:Double, L:Double) -> Double {
48 | return TimeUtils.getSolarTransitJ(ds: ds, M: M, L: L)
49 | }
50 |
51 | @available(*, deprecated: 1.0, message: "will soon become unavailable. Use getHourAngle instead.")
52 | class func getHourAngleH(h:Double, phi:Double, d:Double) -> Double {
53 | return TimeUtils.getHourAngle(h: h, phi: phi, d: d)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------