You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For places where there's a polar day in the given time/date (see the example), isDaytime returns false and isNightTime returns true for all times of day (just opposite to reality).
I know this is an old bug, but I’ve been using Solar extensively for my project Solstice and polar days/nights are so tricky! I’ve figured out a workaround that involves checking whether the coordinates are within a polar circle:
import CoreLocation
import Solar
extensionCLLocationCoordinate2D{varinsideArcticCircle:Bool{ latitude > 66.34 }varinsideAntarcticCircle:Bool{ latitude <-66.34 }varinsidePolarCircle:Bool{ insideArcticCircle || insideAntarcticCircle }}extensionSolar{varisSunUp:Bool{
if sunrise !=nil && sunset !=nil{return isDaytime
}
guard coordinate.insidePolarCircle else{return isDaytime }letmonth=Calendar.current.component(.month, from: date)
switch month {case1...3,10…12:return coordinate.insideAntarcticCircle
default:return coordinate.insideArcticCircle
}}}
This works by:
Returning isDaytime if there is a sunrise/sunset (which is how isDaytime works under the hood anyway)
Checking whether the coordinates lie within a polar circle, and returning isDaytime if they don't
Returning a boolean based on:
a. Which polar circle the coordinates are in
b. Whether the date lies within the northern hemisphere’s winter months
For places where there's a polar day in the given time/date (see the example),
isDaytime
returnsfalse
andisNightTime
returnstrue
for all times of day (just opposite to reality).Code:
Params:
dateTime: 2022-06-03 06:00:00 +0000
coords: lat: 67.94753132376813, lon: 13.131613209843637
The text was updated successfully, but these errors were encountered: