Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates returned could contain NaN time #4

Open
Timac opened this issue May 10, 2023 · 0 comments
Open

Dates returned could contain NaN time #4

Timac opened this issue May 10, 2023 · 0 comments
Assignees

Comments

@Timac
Copy link

Timac commented May 10, 2023

Description

With some longitude and latitude, the SunCalc dates (dawn, dusk, nauticalDawn, night, …) are created with a NaN time. This can lead to unexpected behavior when using this library. This issue can be reproduced if the latitude/longitude is set for example to 89.0/179.0 or 84.0/111.0.

The root problem is caused by the use of acos() with invalid input:

class func getHourAngle(h:Double, phi:Double, d:Double) -> Double {
    return acos((sin(h) - sin(phi) * sin(d)) / (cos(phi) * cos(d)))
}

Note that the original Javascript library also has the same issue, as well as most of the implementations based on this original library. See for example the related issues:

Workaround

One solution would be to implement the fix suggested in the Flutter library: shanus/flutter_suncalc#1
I implemented this workaround in a Swift package port of this code and you can find the commit here: Timac/SunCalc@cad82c3

I am not sure if this code is still under development. Applying this workaround would break the compatibility with old software using this source code.

@shanus shanus self-assigned this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants