Skip to content

Commit

Permalink
Dusk and dawn were inverted (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
davideilmito authored May 3, 2023
1 parent 61dd5fb commit c3c4001
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
59 changes: 29 additions & 30 deletions Sources/SunKit/Sun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))")
}

/*--------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
32 changes: 16 additions & 16 deletions Tests/SunKitTests/UT_Sun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c3c4001

Please sign in to comment.