Closed andris-zalitis closed 7 years ago
One option would be to remove:
let midnight = self.celestialBody.julianDay.midnight
and just use JulianDate
itself, but then we would loose the ability of running code that asks for moonrise/moonset for a local time with hours and minutes, without caring to convert it to local midnight.
Therefore I have opted to use localMidnight(timeZone:)
to solve this. Note that although we already have localMidnight(longitude:)
it does not fully solve the problem because there are differences between midnight calculated based on longitude vs midnight calculated based on time zone.
BTW I've used moonrise/moonset in the example because those change more rapidly from day to day than sunrise/sunset or dawn/dusk.
This is great again, thanks for checking this in details! Again, once we settle the discussion about midnight in #54, I'll happy to merge that work.
Quick note: this isn't settled yet, but I'm still on it. I have tracked down (and down and down...) the problem of rise transit and set times. And it seems, somehow, I don't get right the equatorial coordinates for the date. I'll be in vacations for some time, but I'll be back!
I found the root cause of our problems. I was computing equatorial coordinates of solar system objects based on ecliptic coordinates. But not "normal" (geocentric) ecliptic coordinates, rather the heliocentric ones! I didn't know those latter coords existed anyway.
I had to change a bit the CelestialBody protocol, and I managed to make all tests pass. However, some of them with an accuracy that is not satisfactory. I can't do more for now, as I am leaving for a few vacations. But I am relieved this important issue is solved.
When calculating
RiseTransitSet
we need to have a base date. Resulting rise, transit, set values are from a time range of (base date ..< base date + 24h).Currently the base date is calculated like this:
Let's say we'd like to print moonrise/moonset for year 2017 in Sydney. Even if we pass correct dates (midnights by Sydney timezone) to
let moon = Moon(julianDay: JulianDay(date))
we will still get wrong result because we discard local midnight in our code and so we'll return rise/set for 24h window based on GMT.This code:
Prints:
Notice how rise and set are usually in different dates by Sydney time.
This is how it should look instead.