@@ -39,6 +39,8 @@ public class Sun {
3939 public private( set) var sunset : Date = Date ( )
4040 ///Date of Solar Noon for
4141 public private( set) var solarNoon : Date = Date ( )
42+ ///Date of Solar Midnight
43+ public private( set) var solarMidnight : Date = Date ( )
4244
4345 ///Date at which evening evening Golden hour starts
4446 public private( set) var eveningGoldenHourStart : Date = Date ( )
@@ -108,6 +110,9 @@ public class Sun {
108110 return self . sunHorizonCoordinates. altitude
109111 }
110112
113+ public private( set) var sunEquatorialCoordinates : EquatorialCoordinates = . init( declination: . zero)
114+ public private( set) var sunEclipticCoordinates : EclipticCoordinates = . init( eclipticLatitude: . zero, eclipticLongitude: . zero)
115+
111116 /*--------------------------------------------------------------------
112117 Sun Events during the year
113118 *-------------------------------------------------------------------*/
@@ -180,7 +185,7 @@ public class Sun {
180185
181186 /// Returns True if we are in golden hour range
182187 public var isGoldenHour : Bool {
183- isMorningGoldenHour || isEveningGoldenHour
188+ isMorningGoldenHour || isEveningGoldenHour
184189 }
185190
186191 /// Returns True if we are in evening blue hour range
@@ -195,7 +200,7 @@ public class Sun {
195200
196201 /// Returns True if we are in blue hour range
197202 public var isBlueHour : Bool {
198- isMorningBlueHour || isEveningBlueHour
203+ isMorningBlueHour || isEveningBlueHour
199204 }
200205
201206
@@ -317,6 +322,7 @@ public class Sun {
317322 print ( " Sunrise -> \( dateFormatter. string ( from: sunrise) ) " )
318323 print ( " Sunset -> \( dateFormatter. string ( from: sunset) ) " )
319324 print ( " Solar Noon -> \( dateFormatter. string ( from: solarNoon) ) " )
325+ print ( " Solar Midnight -> \( dateFormatter. string ( from: solarMidnight) ) " )
320326 print ( " Evening Golden Hour Start -> \( dateFormatter. string ( from: eveningGoldenHourStart) ) " )
321327 print ( " Evening Golden Hour End -> \( dateFormatter. string ( from: eveningGoldenHourEnd) ) " )
322328 print ( " Morning Golden Hour Start -> \( dateFormatter. string ( from: morningGoldenHourStart) ) " )
@@ -363,8 +369,7 @@ public class Sun {
363369 }
364370
365371 private var sunHorizonCoordinates : HorizonCoordinates = . init( altitude: . zero, azimuth: . zero)
366- private var sunEquatorialCoordinates : EquatorialCoordinates = . init( declination: . zero)
367- private var sunEclipticCoordinates : EclipticCoordinates = . init( eclipticLatitude: . zero, eclipticLongitude: . zero)
372+
368373
369374 //Sun constants
370375 private let sunEclipticLongitudeAtTheEpoch : Angle = . init( degrees: 280.466069 )
@@ -435,6 +440,7 @@ public class Sun {
435440 self . sunset = getSunset ( ) ?? Date ( )
436441 self . sunsetAzimuth = getSunHorizonCoordinatesFrom ( date: sunset) . azimuth. degrees
437442 self . solarNoon = getSolarNoon ( ) ?? Date ( )
443+ self . solarMidnight = getSolarMidnight ( ) ?? Date ( )
438444 self . solarNoonAzimuth = getSunHorizonCoordinatesFrom ( date: solarNoon) . azimuth. degrees
439445 self . eveningGoldenHourStart = getEveningGoldenHourStart ( ) ?? Date ( )
440446 self . eveningGoldenHourEnd = getEveningGoldenHourEnd ( ) ?? Date ( )
@@ -596,6 +602,23 @@ public class Sun {
596602 return solarNoon
597603 }
598604
605+ /// Computes the solar midnight for self.date.
606+ /// - Returns: Solar midnight time
607+ private func getSolarMidnight( ) -> Date ? {
608+
609+ let secondsForUTCSolarMidnight = ( - 4 * location . coordinate . longitude - equationOfTime) * 60
610+
611+ var calendarUTC : Calendar = . init( identifier: . gregorian)
612+ calendarUTC. timeZone = . init( secondsFromGMT: 0 ) !
613+
614+ let startOfTheDay = calendarUTC. startOfDay ( for: date)
615+
616+ let solarMidnight = startOfTheDay. addingTimeInterval ( secondsForUTCSolarMidnight)
617+
618+ return solarMidnight
619+ }
620+
621+
599622 /// Computes the Sunrise time for self.date
600623 /// - Returns: Sunrise time
601624 private func getSunrise( ) -> Date ? {
0 commit comments