onekiloparsec / SwiftAA

The most comprehensive collection of accurate astronomical algorithms in (C++, Objective-C and) Swift.
http://www.onekiloparsec.dev/
MIT License
171 stars 31 forks source link

Issue with Sunrise/set times #103

Closed treaves closed 3 years ago

treaves commented 3 years ago

I can't explain or understand the values I'm getting for sunrise & sunset. I'm using this code:

import Foundation
import SwiftAA

var cleveland                 = GeographicCoordinates(positivelyWestwardLongitude: Degree(.minus, 81, 40, 52.6440),
                                                      latitude: Degree(.plus, 41, 30, 19.7748),
                                                      altitude: Meter(30))
let timeOffset                = TimeInterval(TimeZone.current.secondsFromGMT())
let date                      = Date(timeIntervalSinceReferenceDate: 632328395.113623) // 2021-01-14 14:46:35

let earth                     = Earth(julianDay: JulianDay(date))

let twilights                 = earth.twilights(forSunAltitude: TwilightSunAltitude.riseAndSet.rawValue,
                                                coordinates: cleveland)
let riseDate                  = twilights.riseTime?.date ?? date
let setDate                   = twilights.setTime?.date ?? date

print("====> date:\(date) timeOffset:\(timeOffset)")
print("====> riseDate:\(riseDate), setDate:\(setDate)") // Should be around 07:50 EST, 17:25 EST

and I receive this output:

====> date:2021-01-14 14:46:35 +0000 timeOffset:-18000.0
====> riseDate:2021-01-14 01:58:14 +0000, setDate:2021-01-14 11:24:27 +0000
Program ended with exit code: 0

If the values took TZ into account, then the values are off by ~-6 hours. If the values are supposed to be UTC (I think they are) then they are off ~-11 hours.

IAny help understanding this would be appreciated.

onekiloparsec commented 3 years ago

Hm... shouldn't the positivelyWestwardLongitude be actually positive ? I suspect a little mistake here.

treaves commented 3 years ago

Yes, I'd just dug into that and noticed. I'd actually had it that way originally, until I started getting some invalid Astronomical Twilights. I'll try to create a test for the later issue, and close this one.

Thanks.

onekiloparsec commented 3 years ago

These twilights are a damn difficult thing. I'd be happy if you provide more tests I can integrate into the codebase.