EDSunriseSet icon indicating copy to clipboard operation
EDSunriseSet copied to clipboard

Midnight sun and polar night

Open danhje opened this issue 10 years ago • 3 comments

Hi Ernesto, great library!

It seems like midnight sun and polar night is not supported. Could you add support for that? I live in Norway, so a large portion of my user base have midnight sun of polar night a large portion of the year.

http://en.wikipedia.org/wiki/Midnight_sun http://en.wikipedia.org/wiki/Polar_night

Seems like the simplest way is to check whether sunrise = sunset. If that is the case, the sun is not rising or setting that day. Then it should be easy to figure out which is the case. If winter, the sun is not rising. If summer, the sun is not setting. Not sure what values should be returned to indicate that a particular day has a midnight sun or is a polar night though.

Daniel

danhje avatar Feb 02 '15 18:02 danhje

Hey Ernesto - awesome piece of code! I am experiencing some trouble unfortunately in that I keep getting nil values when initiation a EDSunriseSet object..Do you have any idea what might cause this? I am checking to make sure I am sending valid coordinates and a timezon. Thanks!

trdavidson avatar Feb 24 '15 19:02 trdavidson

Daniel. A code inspection show that calculateSunriseSunset is distracting a return value that has this information in it. The class could easily be modified to include boolean values for each of these things and have them easily accessible.

bshirley avatar Feb 17 '16 21:02 bshirley

I'm coming late in to the conversation. Perhaps this was addressed since the comment was made. In general, I find no issue with how this is handled. In my testing, what I find is that sunrise and sunset are both set to local midnight. This is perfect for my application, which would have troubles if these objects did not exist. Day length is calculated as time from sunrise to sunset. It works out to approximately 24 hours with these values set. Similarly, nighttime is calculated as time from sunset to the following sunrise. In summer with no sunset, the result is a time interval of 0. But the sunrise and sunset times are nevertheless defined.

Special cases, of course, would be days where there is exactly one of either sunrise or sunset. For my application, no special code is needed. However, the suggestion, above of comparing sunrise to sunset times would not work for these special cases. Instead, each should be compared to local seasonal midnight I think. For these special cases, one but not both would match.

victorengel avatar Sep 14 '17 18:09 victorengel