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

Incorrect results for some calls to Moon.time #81

Closed tallPete closed 5 years ago

tallPete commented 5 years ago

I am getting some incorrect results when trying to fetch the next full moon time when using Moon.time - public func time inside Moon.swift.

Here is some code

            print ("loop begin")
            for index in 1...20 {
                calculationDate = Calendar.current.date(byAdding: .day, value: index, to: Date())!
                print("calcdate, next fullmoon",calculationDate, Moon(julianDay:JulianDay(calculationDate)).time(of: .fullMoon, forward: true, mean: false).date)
            }
            print ("end loop")

and here is the result

loop begin
calcdate, next fullmoon 2019-02-09 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-10 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-11 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-12 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-13 09:01:26 +0000 2019-02-19 15:54:38 +0000
calcdate, next fullmoon 2019-02-14 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-15 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-16 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-17 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-18 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-19 09:01:26 +0000 2019-03-21 01:44:00 +0000 <<incorrect
calcdate, next fullmoon 2019-02-20 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-21 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-22 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-23 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-24 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-25 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-26 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-27 09:01:26 +0000 2019-03-21 01:44:00 +0000
calcdate, next fullmoon 2019-02-28 09:01:26 +0000 2019-03-21 01:44:00 +0000
end loop

I have marked some lines as incorrect above, they show the next full moon as being on the 21st March, whereas the next full moon is actually still to come on 19th February. I haven't worked out the root cause of the issue yet, whether it is in SwiftAA or AA+, but I thought I would report it here. Cheers.

onekiloparsec commented 5 years ago

Hi. Thanks a lot for the bug report. It looks like the algorithms don't switch from one full moon to the next at the right moment. Will look into it.

onekiloparsec commented 5 years ago

As far as I can tell, this is now fixed (see 9a0937654a02e0e4ce42bffc00d549a9de7a63b5). And a Unit Test covers it. That was a simple floor/round error. Thanks again for your bug report!

The Pod is also updated.

tallPete commented 5 years ago

Thank you to the generous folk who have fixed this. It is indeed resolved for all cases I have tested. Thanks again.