-
Notifications
You must be signed in to change notification settings - Fork 82
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
Adding of 1 day to sunrise and sunset times happens too early #24
Comments
I found a workaround that works for me for the moment. I basically strip the date component from the dates and only use the time components. It's not that precise as it could compare the current date/time to the sunrise & sunset time of tomorrow, but that's ok for my usage (I use it to switch App color theme at sunset / sunrise). It's not fail safe as it doesn't work for very northern / very southern locations where the sunset is after midnight / sunrise if before midnight or even doesn't set or rise at all, so a fix or other workaround would be appreciated. Here it is:
And the date extension:
|
Thank you guidove, my use case matches yours and your solution helps. |
Hi @guidove! Thank you for the report. Just to help me pin down this bug and implement a correct fix, would you mind creating a failing test that represents your scenario? This would help tons! |
Sorry, do not have any experience with making tests. But it's very easy to reproduce by feeding it the lat & lon mentioned above (is Mex city coordinate) and you'll need to set your device timezone to Mexico city as well probably. Then print out calculated sunrise and sunset date&time and compare them to the official ones. (Just Google 'mexico city sunrise sunset' and it will tell you right in the search results.) |
I had encountered this and had a fix in my fork |
This solved the problem for me. I hope that this fix is not affected by daylight savings.
|
I'm in mexico city and noticed that the isDayTime returns false at exactly 18:00 local time (12:00 UTC) while current sunset time is around 20:15. After some analyses I found out that, at exactly that 12:00 UTC, the sunrise and sunset days are shifted one day forward. This results in both sunrise and sunset being later than the current time, which results in false for isDayTime.
I'm assuming this 1 day shift should only happen after sunset, right?
I really appreciate what you've done, and, honestly it goes a bit over my head. I understand that eventually the result of this code is probably wrong:
but I guess it's also very well possible, that is somewhere in the code above these lines.
These are the values for lngHour & UT (after normalisation) for sunrise and sunset respectively, in my location, mexico city:
I could work around this by adding a day to the currentTime calculation if date > 12:00 UTC, but I'm not sure is a good idea. From what I've seen here it works for most people, so might be something with my location specifically, while the App I'm using this in is used all over the world.
Any thoughts to a fix or workaround?
The text was updated successfully, but these errors were encountered: