Skip to content

Commit cce6e9d

Browse files
authored
Changed names (#36)
1 parent 2976f94 commit cce6e9d

File tree

3 files changed

+150
-129
lines changed

3 files changed

+150
-129
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ mySun.sunrise
6060
mySun.sunset
6161

6262
// Evening Golden Hour Start Date
63-
mySun.goldenHourStart
63+
mySun.eveningGoldenHourStart
6464

6565
// Evening Golden Hour End Date
66-
mySun.goldenHourEnd
66+
mySun.eveningGoldenHourEnd
6767

6868
// To know all the information you can retrieve go to the **Features** section.
6969

@@ -96,17 +96,17 @@ To properly show the Sun Date Events use the following DateFormatter.
9696
## Features
9797
* Sun Azimuth
9898
* Sun Altitude
99-
* First Light Time
100-
* Last Light Time
99+
* Civil Dusk Time
100+
* Civil Dawn Time
101101
* Sunrise Time
102102
* Solar Noon Time
103103
* Morning Golden Hour Time
104104
* Evening Golden Hour Time
105105
* Sunset Time
106-
* Astronomical Sunrise
107-
* Astronomical Sunset
108-
* Nautical Sunrise
109-
* Nautical Sunset
106+
* Astronomical Dusk
107+
* Astronomical Dawn
108+
* Nautical Dusk
109+
* Nautical Down
110110
* Morning Blue Hour Time
111111
* Evening Blue Hour Time
112112
* Sun Azimuth at Sunrise

Sources/SunKit/Sun.swift

Lines changed: 102 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,34 @@ public class Sun {
4141
public private(set) var solarNoon: Date = Date()
4242

4343
///Date at which evening evening Golden hour starts
44-
public private(set) var goldenHourStart: Date = Date()
44+
public private(set) var eveningGoldenHourStart: Date = Date()
4545
///Date at which evening evening Golden hour ends
46-
public private(set) var goldenHourEnd: Date = Date()
46+
public private(set) var eveningGoldenHourEnd: Date = Date()
4747

4848
///Date at which evening Morning Golden hour starts
4949
public private(set) var morningGoldenHourStart: Date = Date()
5050
///Date at which evening Morning Golden hour ends
5151
public private(set) var morningGoldenHourEnd: Date = Date()
5252

5353

54-
///Date at which there is the first light, also known as Civil Sunrise
55-
public private(set) var firstLight: Date = Date()
56-
///Date at which there is the last light, also known as Civil Sunset
57-
public private(set) var lastLight: Date = Date()
54+
///Date at which there is the Civil Dusk
55+
public private(set) var civilDusk: Date = Date()
56+
///Date at which there is the Civil Dawn
57+
public private(set) var civilDawn: Date = Date()
5858

59-
///Date at which there is the Nautical Sunrise
60-
public private(set) var nauticalSunrise: Date = Date()
61-
///Date at which there is the Nautical Sunset
62-
public private(set) var nauticalSunset: Date = Date()
59+
///Date at which there is the Nautical Dusk
60+
public private(set) var nauticalDusk: Date = Date()
61+
///Date at which there is the Nautical Down
62+
public private(set) var nauticalDown: Date = Date()
6363

64-
///Date at which there is the Astronomical Sunrise
65-
public private(set) var astronomicalSunrise: Date = Date()
66-
///Date at which there is the Astronomical Sunset
67-
public private(set) var astronomicalSunset: Date = Date()
64+
///Date at which there is the Astronomical Dusk
65+
public private(set) var astronomicalDusk: Date = Date()
66+
///Date at which there is the Astronomical Dawn
67+
public private(set) var astronomicalDawn: Date = Date()
6868

69-
///Date at which morning Blue Hour starts. Sun at -6 degrees elevation = firstLight
69+
///Date at which morning Blue Hour starts. Sun at -6 degrees elevation = civil dusk
7070
public var morningBlueHourStart: Date{
71-
return firstLight
71+
return civilDusk
7272
}
7373

7474
///Date at which morning Blue Hour ends. Sun at -4 degrees elevation = morning golden hour start
@@ -78,12 +78,12 @@ public class Sun {
7878

7979
///Date at which evening Blue Hour starts. Sun at -4 degrees elevation = evening golden hour end
8080
public var eveningBlueHourStart: Date{
81-
return goldenHourEnd
81+
return eveningGoldenHourEnd
8282
}
8383

84-
///Date at which morning Blue Hour ends. Sun at -6 degrees elevation = last light
84+
///Date at which morning Blue Hour ends. Sun at -6 degrees elevation = Civil Dawn
8585
public var eveningBlueHourEnd: Date {
86-
return lastLight
86+
return civilDawn
8787
}
8888

8989

@@ -157,27 +157,48 @@ public class Sun {
157157
/// Returns True if is night
158158
public var isNight: Bool {
159159
if !isCircumPolar {
160-
return date < firstLight || date > lastLight
160+
return date < civilDusk || date > civilDawn
161161
} else {
162162
return isAlwaysNight
163163
}
164164
}
165165

166-
/// Returns True if is sunrise
167-
public var isSunrise: Bool {
168-
date >= firstLight && date <= sunrise
166+
/// Returns True if is twilight time
167+
public var isTwilight: Bool {
168+
(astronomicalDusk <= date && date <= sunrise) || (sunset <= date && date <= astronomicalDawn)
169169
}
170170

171-
/// Returns True if is sunset
172-
public var isSunset: Bool {
173-
date >= sunset && date <= lastLight
171+
/// Returns True if we are in evening golden hour range
172+
public var isEveningGoldenHour: Bool {
173+
date.timeIntervalSince(eveningGoldenHourStart) >= 0 && eveningGoldenHourEnd.timeIntervalSince(date) >= 0
174174
}
175175

176-
/// Returns True if we are in evening golden hour range
176+
/// Returns True if we are in morning golden hour range
177+
public var isMorningGoldenHour: Bool {
178+
date.timeIntervalSince(morningBlueHourStart) >= 0 && morningBlueHourEnd.timeIntervalSince(date) >= 0
179+
}
180+
181+
/// Returns True if we are in golden hour range
177182
public var isGoldenHour: Bool {
178-
date.timeIntervalSince(goldenHourStart) >= 0 && goldenHourEnd.timeIntervalSince(date) >= 0
183+
isMorningGoldenHour || isEveningGoldenHour
184+
}
185+
186+
/// Returns True if we are in evening blue hour range
187+
public var isEveningBlueHour: Bool {
188+
date.timeIntervalSince(eveningBlueHourStart) >= 0 && eveningBlueHourEnd.timeIntervalSince(date) >= 0
179189
}
180190

191+
/// Returns True if we are in morning blue hour range
192+
public var isMorningBlueHour: Bool {
193+
date.timeIntervalSince(morningBlueHourStart) >= 0 && morningBlueHourEnd.timeIntervalSince(date) >= 0
194+
}
195+
196+
/// Returns True if we are in blue hour range
197+
public var isBlueHour: Bool {
198+
isMorningBlueHour || isEveningBlueHour
199+
}
200+
201+
181202
/// Returns true if we are near the pole and we are in a situation in which Sun Events during the day could have no meaning
182203
public var isCircumPolar: Bool {
183204
isAlwaysLight || isAlwaysNight
@@ -296,16 +317,16 @@ public class Sun {
296317
print("Sunrise -> \(dateFormatter.string(from: sunrise))")
297318
print("Sunset -> \(dateFormatter.string(from: sunset))")
298319
print("Solar Noon -> \(dateFormatter.string(from: solarNoon))")
299-
print("evening Golden Hour Start -> \(dateFormatter.string(from: goldenHourStart))")
300-
print("evening Golden Hour End -> \(dateFormatter.string(from: goldenHourEnd))")
320+
print("Evening Golden Hour Start -> \(dateFormatter.string(from: eveningGoldenHourStart))")
321+
print("Evening Golden Hour End -> \(dateFormatter.string(from: eveningGoldenHourEnd))")
301322
print("Morning Golden Hour Start -> \(dateFormatter.string(from: morningGoldenHourStart))")
302323
print("Morning Golden Hour End -> \(dateFormatter.string(from: morningGoldenHourEnd))")
303-
print("First Light -> \(dateFormatter.string(from: firstLight))")
304-
print("Last Light -> \(dateFormatter.string(from: lastLight))")
305-
print("Nautical Sunrise -> \(dateFormatter.string(from: nauticalSunrise))")
306-
print("Nautical Sunset -> \(dateFormatter.string(from: nauticalSunset))")
307-
print("Astronomical Sunrise -> \(dateFormatter.string(from: astronomicalSunrise))")
308-
print("Astronomical Sunset -> \(dateFormatter.string(from: astronomicalSunset))")
324+
print("Civil dusk -> \(dateFormatter.string(from: civilDusk))")
325+
print("Civil Dawn -> \(dateFormatter.string(from: civilDawn))")
326+
print("Nautical Dusk -> \(dateFormatter.string(from: nauticalDusk))")
327+
print("Nautical Down -> \(dateFormatter.string(from: nauticalDown))")
328+
print("Astronomical Dusk -> \(dateFormatter.string(from: astronomicalDusk))")
329+
print("Astronomical Dawn -> \(dateFormatter.string(from: astronomicalDawn))")
309330
print("Morning Blue Hour Start -> \(dateFormatter.string(from: morningBlueHourStart))")
310331
print("Morning Blue Hour End -> \(dateFormatter.string(from: morningBlueHourEnd))")
311332
print("evening Blue Hour Start -> \(dateFormatter.string(from: eveningBlueHourStart))")
@@ -403,7 +424,7 @@ public class Sun {
403424
/// Then get rise, set and noon times and their relative azimuths in degrees.
404425
/// Compute Solar noon.
405426
/// Compute Golden hour start and end time.
406-
/// Compute first light and last light time
427+
/// Compute civil dusk and Civil Dawn time
407428
///
408429
/// - Parameter needToComputeAgainSunEvents: True if Sunrise,Sunset and all the others daily sun events have to be computed.
409430
private func refresh(needToComputeSunEvents: Bool = true) {
@@ -416,14 +437,14 @@ public class Sun {
416437
self.sunsetAzimuth = getSunHorizonCoordinatesFrom(date: sunset).azimuth.degrees
417438
self.solarNoon = getSolarNoon() ?? Date()
418439
self.solarNoonAzimuth = getSunHorizonCoordinatesFrom(date: solarNoon).azimuth.degrees
419-
self.goldenHourStart = getGoldenHourStart() ?? Date()
420-
self.goldenHourEnd = getGoldenHourFinish() ?? Date()
421-
self.firstLight = getFirstLight() ?? Date()
422-
self.lastLight = getLastLight() ?? Date()
423-
self.nauticalSunrise = getNauticalSunrise() ?? Date()
424-
self.nauticalSunset = getNauticalSunset() ?? Date()
425-
self.astronomicalSunrise = getAstronomicalSunrise() ?? Date()
426-
self.astronomicalSunset = getAstronomicalSunset() ?? Date()
440+
self.eveningGoldenHourStart = getEveningGoldenHourStart() ?? Date()
441+
self.eveningGoldenHourEnd = getEveningGoldenHourEnd() ?? Date()
442+
self.civilDusk = getCivilDusk() ?? Date()
443+
self.civilDawn = getCivilDawn() ?? Date()
444+
self.nauticalDusk = getNauticalDusk() ?? Date()
445+
self.nauticalDown = getNauticalDown() ?? Date()
446+
self.astronomicalDusk = getAstronomicalDusk() ?? Date()
447+
self.astronomicalDawn = getAstronomicalDawn() ?? Date()
427448
self.morningGoldenHourStart = getMorningGoldenHourStart() ?? Date()
428449
self.morningGoldenHourEnd = getMorningGoldenHourEnd() ?? Date()
429450

@@ -627,8 +648,8 @@ public class Sun {
627648
/// - Returns: Time at which the Sun reaches that elevation. Nil if it didn't find it.
628649
private func getDateFrom(sunEvent : SunElevationEvents, morning: Bool = false) -> Date? {
629650

630-
let elevationSunFirstLight: Angle = .degrees(sunEvent.rawValue)
631-
var cosHra = (sin(elevationSunFirstLight.radians) - sin(sunEquatorialCoordinates.declination.radians) * sin(latitude.radians)) / (cos(sunEquatorialCoordinates.declination.radians) * cos(latitude.radians))
651+
let elevationSun: Angle = .degrees(sunEvent.rawValue)
652+
var cosHra = (sin(elevationSun.radians) - sin(sunEquatorialCoordinates.declination.radians) * sin(latitude.radians)) / (cos(sunEquatorialCoordinates.declination.radians) * cos(latitude.radians))
632653
cosHra = clamp(lower: -1, upper: 1, number: cosHra)
633654
let hraAngle: Angle = .radians(acos(cosHra))
634655
var secondsForSunToReachElevation = (morning ? -1 : 1) * (hraAngle.degrees / 15) * SECONDS_IN_ONE_HOUR + TWELVE_HOUR_IN_SECONDS - timeCorrectionFactorInSeconds
@@ -654,76 +675,76 @@ public class Sun {
654675

655676
/// Golden Hour in the evening begins when the sun reaches elevation equals to 6 degrees
656677
/// - Returns: Time at which the GoldenHour starts
657-
private func getGoldenHourStart() -> Date? {
658-
guard let goldenHourStart = getDateFrom(sunEvent: .eveningGoldenHourStart) else {
678+
private func getEveningGoldenHourStart() -> Date? {
679+
guard let eveningGoldenHourStart = getDateFrom(sunEvent: .eveningGoldenHourStart) else {
659680
return nil
660681
}
661682

662-
return goldenHourStart
683+
return eveningGoldenHourStart
663684
}
664685

665686
/// Golden Hour in the evening ends when the sun reaches elevation equals to -4 degrees
666687
/// - Returns: Time at which the GoldenHour ends
667-
private func getGoldenHourFinish() -> Date? {
688+
private func getEveningGoldenHourEnd() -> Date? {
668689
guard let goldenHourFinish = getDateFrom(sunEvent: .eveningGoldenHourEnd) else {
669690
return nil
670691
}
671692

672693
return goldenHourFinish
673694
}
674695

675-
/// Last light is when the Sun reaches -6 degrees of elevation. Also known as civil sunset.
676-
/// - Returns: Last light time
677-
private func getLastLight() -> Date? {
678-
guard let lastLight = getDateFrom(sunEvent: .civil) else {
696+
/// Civil Dawn is when the Sun reaches -6 degrees of elevation. Also known as civil sunset.
697+
/// - Returns: Civil Dawn time
698+
private func getCivilDawn() -> Date? {
699+
guard let civilDawn = getDateFrom(sunEvent: .civil) else {
679700
return nil
680701
}
681-
return lastLight
702+
return civilDawn
682703
}
683704

684-
/// First light is when the Sun reaches -6 degrees of elevation. Also known as civil sunrise.
685-
/// - Returns: First light time
686-
private func getFirstLight() -> Date? {
687-
guard let firstLight = getDateFrom(sunEvent: .civil, morning: true) else {
705+
/// civil dusk is when the Sun reaches -6 degrees of elevation. Also known as civil sunrise.
706+
/// - Returns: civil dusk time
707+
private func getCivilDusk() -> Date? {
708+
guard let civilDusk = getDateFrom(sunEvent: .civil, morning: true) else {
688709
return nil
689710
}
690-
return firstLight
711+
return civilDusk
691712
}
692713

693-
/// Nautical Sunrise is when the Sun reaches -12 degrees of elevation.
694-
/// - Returns: Nautical Sunrise
695-
private func getNauticalSunrise() -> Date? {
696-
guard let nauticalSunrise = getDateFrom(sunEvent: .nautical, morning: true) else {
714+
/// Nautical Dusk is when the Sun reaches -12 degrees of elevation.
715+
/// - Returns: Nautical Dusk
716+
private func getNauticalDusk() -> Date? {
717+
guard let nauticalDusk = getDateFrom(sunEvent: .nautical, morning: true) else {
697718
return nil
698719
}
699-
return nauticalSunrise
720+
return nauticalDusk
700721
}
701722

702-
/// Nautical Sunrise is when the Sun reaches -12 degrees of elevation.
703-
/// - Returns: Nautical Sunset
704-
private func getNauticalSunset() -> Date? {
705-
guard let nauticalSunset = getDateFrom(sunEvent: .nautical, morning: false) else {
723+
/// Nautical Dusk is when the Sun reaches -12 degrees of elevation.
724+
/// - Returns: Nautical Down
725+
private func getNauticalDown() -> Date? {
726+
guard let nauticalDown = getDateFrom(sunEvent: .nautical, morning: false) else {
706727
return nil
707728
}
708-
return nauticalSunset
729+
return nauticalDown
709730
}
710731

711-
/// Astronomical Sunrise is when the Sun reaches -18 degrees of elevation.
712-
/// - Returns: Nautical Sunrise
713-
private func getAstronomicalSunrise() -> Date? {
714-
guard let nauticalSunrise = getDateFrom(sunEvent: .astronomical, morning: true) else {
732+
/// Astronomical Dusk is when the Sun reaches -18 degrees of elevation.
733+
/// - Returns: Astronomical Dusk
734+
private func getAstronomicalDusk() -> Date? {
735+
guard let astronomicalDusk = getDateFrom(sunEvent: .astronomical, morning: true) else {
715736
return nil
716737
}
717-
return nauticalSunrise
738+
return astronomicalDusk
718739
}
719740

720-
/// Astronomical Sunset is when the Sun reaches -18 degrees of elevation.
721-
/// - Returns: Nautical Sunset
722-
private func getAstronomicalSunset() -> Date? {
723-
guard let nauticalSunset = getDateFrom(sunEvent: .astronomical, morning: false) else {
741+
/// Astronomical Dawn is when the Sun reaches -18 degrees of elevation.
742+
/// - Returns: Astronomical Dawn
743+
private func getAstronomicalDawn() -> Date? {
744+
guard let astronomicalDawn = getDateFrom(sunEvent: .astronomical, morning: false) else {
724745
return nil
725746
}
726-
return nauticalSunset
747+
return astronomicalDawn
727748
}
728749

729750
/// Morning Golden Hour start when Sun reaches -4 degress of elevation

0 commit comments

Comments
 (0)