From c3c40014ae9980735332e6a2e9ba5e551bc0093b Mon Sep 17 00:00:00 2001 From: Davide Biancardi <81416309+davideilmito@users.noreply.github.com> Date: Wed, 3 May 2023 15:40:24 +0200 Subject: [PATCH] Dusk and dawn were inverted (#41) --- Sources/SunKit/Sun.swift | 59 +++++++++++++++++----------------- Tests/SunKitTests/UT_Sun.swift | 32 +++++++++--------- 2 files changed, 45 insertions(+), 46 deletions(-) diff --git a/Sources/SunKit/Sun.swift b/Sources/SunKit/Sun.swift index 973e740..a8980b1 100644 --- a/Sources/SunKit/Sun.swift +++ b/Sources/SunKit/Sun.swift @@ -68,7 +68,7 @@ public class Sun { ///Date at which morning Blue Hour starts. Sun at -6 degrees elevation = civil dusk public var morningBlueHourStart: Date{ - return civilDusk + return civilDawn } ///Date at which morning Blue Hour ends. Sun at -4 degrees elevation = morning golden hour start @@ -83,7 +83,7 @@ public class Sun { ///Date at which morning Blue Hour ends. Sun at -6 degrees elevation = Civil Dawn public var eveningBlueHourEnd: Date { - return civilDawn + return civilDusk } @@ -165,7 +165,7 @@ public class Sun { /// Returns True if is twilight time public var isTwilight: Bool { - (astronomicalDusk <= date && date < sunrise) || (sunset < date && date <= astronomicalDawn) + (astronomicalDawn <= date && date < sunrise) || (sunset < date && date <= astronomicalDusk) } /// Returns True if we are in evening golden hour range @@ -313,30 +313,29 @@ public class Sun { /// Dumps all the Sun Events dates public func dumpDateInfos(){ - print("Current Date -> \(dateFormatter.string(from: date))") - print("Sunrise -> \(dateFormatter.string(from: sunrise))") - print("Sunset -> \(dateFormatter.string(from: sunset))") - print("Solar Noon -> \(dateFormatter.string(from: solarNoon))") + print("Current Date -> \(dateFormatter.string(from: date))") + print("Sunrise -> \(dateFormatter.string(from: sunrise))") + print("Sunset -> \(dateFormatter.string(from: sunset))") + print("Solar Noon -> \(dateFormatter.string(from: solarNoon))") print("Evening Golden Hour Start -> \(dateFormatter.string(from: eveningGoldenHourStart))") print("Evening Golden Hour End -> \(dateFormatter.string(from: eveningGoldenHourEnd))") print("Morning Golden Hour Start -> \(dateFormatter.string(from: morningGoldenHourStart))") print("Morning Golden Hour End -> \(dateFormatter.string(from: morningGoldenHourEnd))") - print("Civil dusk -> \(dateFormatter.string(from: civilDusk))") - print("Civil Dawn -> \(dateFormatter.string(from: civilDawn))") - print("Nautical Dusk -> \(dateFormatter.string(from: nauticalDusk))") - print("Nautical Dawn -> \(dateFormatter.string(from: nauticalDawn))") - print("Astronomical Dusk -> \(dateFormatter.string(from: astronomicalDusk))") - print("Astronomical Dawn -> \(dateFormatter.string(from: astronomicalDawn))") - print("Morning Blue Hour Start -> \(dateFormatter.string(from: morningBlueHourStart))") - print("Morning Blue Hour End -> \(dateFormatter.string(from: morningBlueHourEnd))") - print("evening Blue Hour Start -> \(dateFormatter.string(from: eveningBlueHourStart))") - print("evening Blue Hour End -> \(dateFormatter.string(from: eveningBlueHourEnd))") - - print("March Equinox -> \(dateFormatter.string(from: marchEquinox))") - print("June Solstice -> \(dateFormatter.string(from: juneSolstice))") - print("September Equinox -> \(dateFormatter.string(from: septemberEquinox))") - print("December Solstice -> \(dateFormatter.string(from: decemberSolstice))") - + print("Civil dusk -> \(dateFormatter.string(from: civilDusk))") + print("Civil Dawn -> \(dateFormatter.string(from: civilDawn))") + print("Nautical Dusk -> \(dateFormatter.string(from: nauticalDusk))") + print("Nautical Dawn -> \(dateFormatter.string(from: nauticalDawn))") + print("Astronomical Dusk -> \(dateFormatter.string(from: astronomicalDusk))") + print("Astronomical Dawn -> \(dateFormatter.string(from: astronomicalDawn))") + print("Morning Blue Hour Start -> \(dateFormatter.string(from: morningBlueHourStart))") + print("Morning Blue Hour End -> \(dateFormatter.string(from: morningBlueHourEnd))") + print("evening Blue Hour Start -> \(dateFormatter.string(from: eveningBlueHourStart))") + print("evening Blue Hour End -> \(dateFormatter.string(from: eveningBlueHourEnd))") + + print("March Equinox -> \(dateFormatter.string(from: marchEquinox))") + print("June Solstice -> \(dateFormatter.string(from: juneSolstice))") + print("September Equinox -> \(dateFormatter.string(from: septemberEquinox))") + print("December Solstice -> \(dateFormatter.string(from: decemberSolstice))") } /*-------------------------------------------------------------------- @@ -693,10 +692,10 @@ public class Sun { return goldenHourFinish } - /// Civil Dawn is when the Sun reaches -6 degrees of elevation. Also known as civil sunset. + /// Civil Dawn is when the Sun reaches -6 degrees of elevation. Also known as civil sunrise /// - Returns: Civil Dawn time private func getCivilDawn() -> Date? { - guard let civilDawn = getDateFrom(sunEvent: .civil) else { + guard let civilDawn = getDateFrom(sunEvent: .civil,morning: true) else { return nil } return civilDawn @@ -705,7 +704,7 @@ public class Sun { /// civil dusk is when the Sun reaches -6 degrees of elevation. Also known as civil sunrise. /// - Returns: civil dusk time private func getCivilDusk() -> Date? { - guard let civilDusk = getDateFrom(sunEvent: .civil, morning: true) else { + guard let civilDusk = getDateFrom(sunEvent: .civil, morning: false) else { return nil } return civilDusk @@ -714,7 +713,7 @@ public class Sun { /// Nautical Dusk is when the Sun reaches -12 degrees of elevation. /// - Returns: Nautical Dusk private func getNauticalDusk() -> Date? { - guard let nauticalDusk = getDateFrom(sunEvent: .nautical, morning: true) else { + guard let nauticalDusk = getDateFrom(sunEvent: .nautical, morning: false) else { return nil } return nauticalDusk @@ -723,7 +722,7 @@ public class Sun { /// Nautical Dusk is when the Sun reaches -12 degrees of elevation. /// - Returns: Nautical Dawn private func getNauticalDawn() -> Date? { - guard let nauticalDawn = getDateFrom(sunEvent: .nautical, morning: false) else { + guard let nauticalDawn = getDateFrom(sunEvent: .nautical, morning: true) else { return nil } return nauticalDawn @@ -732,7 +731,7 @@ public class Sun { /// Astronomical Dusk is when the Sun reaches -18 degrees of elevation. /// - Returns: Astronomical Dusk private func getAstronomicalDusk() -> Date? { - guard let astronomicalDusk = getDateFrom(sunEvent: .astronomical, morning: true) else { + guard let astronomicalDusk = getDateFrom(sunEvent: .astronomical, morning: false) else { return nil } return astronomicalDusk @@ -741,7 +740,7 @@ public class Sun { /// Astronomical Dawn is when the Sun reaches -18 degrees of elevation. /// - Returns: Astronomical Dawn private func getAstronomicalDawn() -> Date? { - guard let astronomicalDawn = getDateFrom(sunEvent: .astronomical, morning: false) else { + guard let astronomicalDawn = getDateFrom(sunEvent: .astronomical, morning: true) else { return nil } return astronomicalDawn diff --git a/Tests/SunKitTests/UT_Sun.swift b/Tests/SunKitTests/UT_Sun.swift index 4407f8f..4af9635 100644 --- a/Tests/SunKitTests/UT_Sun.swift +++ b/Tests/SunKitTests/UT_Sun.swift @@ -93,18 +93,18 @@ final class UT_Sun: XCTestCase { var expectedGoldenHourStart = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 16, minute: 00, seconds: 00,timeZone: timeZoneUnderTest) var expectedGoldenHourEnd = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 16, minute: 59, seconds: 00,timeZone: timeZoneUnderTest) - var expectedcivilDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 6, minute: 24, seconds: 51,timeZone: timeZoneUnderTest) - var expectedcivilDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 17, minute: 11, seconds: 28,timeZone: timeZoneUnderTest) + var expectedcivilDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 6, minute: 24, seconds: 51,timeZone: timeZoneUnderTest) + var expectedcivilDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 17, minute: 11, seconds: 28,timeZone: timeZoneUnderTest) var expectedSolarNoon = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 11, minute: 48, seconds: 21,timeZone: timeZoneUnderTest) - var expectednauticalDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 5, minute: 52, seconds: 21,timeZone: timeZoneUnderTest) + var expectednauticalDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 5, minute: 52, seconds: 21,timeZone: timeZoneUnderTest) - var expectednauticalDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 17, minute: 44, seconds: 45,timeZone: timeZoneUnderTest) + var expectednauticalDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 17, minute: 44, seconds: 45,timeZone: timeZoneUnderTest) - var expectedastronomicalDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 5, minute: 19, seconds: 25,timeZone: timeZoneUnderTest) + var expectedastronomicalDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 5, minute: 19, seconds: 25,timeZone: timeZoneUnderTest) - var expectedastronomicalDawn = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 18, minute: 17, seconds: 20,timeZone: timeZoneUnderTest) + var expectedastronomicalDusk = createDateCustomTimeZone(day: 19, month: 11, year: 2022, hour: 18, minute: 17, seconds: 20,timeZone: timeZoneUnderTest) //Step4: Check if the output are close to the expected ones @@ -152,8 +152,8 @@ final class UT_Sun: XCTestCase { expectedGoldenHourStart = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 16, minute: 02, seconds: 00,timeZone: timeZoneUnderTest) expectedGoldenHourEnd = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 17, minute: 05, seconds: 00,timeZone: timeZoneUnderTest) - expectedcivilDusk = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 6, minute: 56, seconds: 24,timeZone: timeZoneUnderTest) - expectedcivilDawn = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 17, minute: 16, seconds: 06,timeZone: timeZoneUnderTest) + expectedcivilDawn = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 6, minute: 56, seconds: 24,timeZone: timeZoneUnderTest) + expectedcivilDusk = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 17, minute: 16, seconds: 06,timeZone: timeZoneUnderTest) expectedSolarNoon = createDateCustomTimeZone(day: 31, month: 12, year: 2024, hour: 12, minute: 06, seconds: 11,timeZone: timeZoneUnderTest) @@ -198,8 +198,8 @@ final class UT_Sun: XCTestCase { expectedGoldenHourStart = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 18, minute: 11, seconds: 00,timeZone: timeZoneUnderTest) expectedGoldenHourEnd = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 19, minute: 04, seconds: 00,timeZone: timeZoneUnderTest) - expectedcivilDusk = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 4, minute: 20, seconds: 39,timeZone: timeZoneUnderTest) - expectedcivilDawn = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 19, minute: 14, seconds: 00,timeZone: timeZoneUnderTest) + expectedcivilDawn = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 4, minute: 20, seconds: 39,timeZone: timeZoneUnderTest) + expectedcivilDusk = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 19, minute: 14, seconds: 00,timeZone: timeZoneUnderTest) expectedSolarNoon = createDateCustomTimeZone(day: 1, month: 8, year: 2022, hour: 11, minute: 47, seconds: 36,timeZone: timeZoneUnderTest) @@ -243,8 +243,8 @@ final class UT_Sun: XCTestCase { expectedGoldenHourStart = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 16, minute: 22, seconds: 00,timeZone: timeZoneUnderTest) expectedGoldenHourEnd = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 17, minute: 22, seconds: 00,timeZone: timeZoneUnderTest) - expectedcivilDusk = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 6, minute: 58, seconds: 28,timeZone: timeZoneUnderTest) - expectedcivilDawn = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 17, minute: 32, seconds: 27,timeZone: timeZoneUnderTest) + expectedcivilDawn = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 6, minute: 58, seconds: 28,timeZone: timeZoneUnderTest) + expectedcivilDusk = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 17, minute: 32, seconds: 27,timeZone: timeZoneUnderTest) expectedSolarNoon = createDateCustomTimeZone(day: 1, month: 1, year: 2015, hour: 12, minute: 15, seconds: 23,timeZone: timeZoneUnderTest) @@ -284,8 +284,8 @@ final class UT_Sun: XCTestCase { expectedSunRise = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 10, minute: 41, seconds: 46,timeZone: timeZoneUnderTest) expectedSunset = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 13, minute: 08, seconds: 48,timeZone: timeZoneUnderTest) - expectedcivilDusk = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 08, minute: 45, seconds: 30,timeZone: timeZoneUnderTest) - expectedcivilDawn = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 15, minute: 05, seconds: 08,timeZone: timeZoneUnderTest) + expectedcivilDawn = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 08, minute: 45, seconds: 30,timeZone: timeZoneUnderTest) + expectedcivilDusk = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 15, minute: 05, seconds: 08,timeZone: timeZoneUnderTest) expectedSolarNoon = createDateCustomTimeZone(day: 19, month: 1, year: 2022, hour: 11, minute: 54, seconds: 52,timeZone: timeZoneUnderTest) @@ -321,8 +321,8 @@ final class UT_Sun: XCTestCase { expectedSunRise = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 6, minute: 49, seconds: 35,timeZone: timeZoneUnderTest) expectedSunset = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 18, minute: 47, seconds: 42,timeZone: timeZoneUnderTest) - expectedcivilDusk = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 6, minute: 27, seconds: 59,timeZone: timeZoneUnderTest) - expectedcivilDawn = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 19, minute: 09, seconds: 19,timeZone: timeZoneUnderTest) + expectedcivilDawn = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 6, minute: 27, seconds: 59,timeZone: timeZoneUnderTest) + expectedcivilDusk = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 19, minute: 09, seconds: 19,timeZone: timeZoneUnderTest) expectedSolarNoon = createDateCustomTimeZone(day: 12, month: 3, year: 2023, hour: 12, minute: 48, seconds: 31,timeZone: timeZoneUnderTest)