Calculating the sunrise and sunset in Scala following the Sunrise equation.
Edge cases Since places within the polar circles might experience Midnight Sun or Polar Night, sunrise or sunset are actually optional for certain places.
Dependencies
resolvers += Resolver.bintrayRepo("oschrenk", "maven")
libraryDependencies += "com.oschrenk.spacetime" %% "sunrise-scala" % "0.5.1"
Your application
import com.oschrenk.spacetime.sunrise.SunriseSunset
// Amsterdam
val latitude = 52.366667
val longitude = 4.9
val zoneId: ZoneId = ZoneId.of("Europe/Amsterdam")
val date: LocalDate = LocalDate.of(2017, 5, 22)
SunriseSunset.of(latitude, longitude, date, zoneId) match {
case Day(sunrise,sunset) =>
println(sunrise) // 2017-05-22T05:39:09+02:00[Europe/Amsterdam]
println(sunset) // 2017-05-22T21:37:34+02:00[Europe/Amsterdam]
case PolarDay =>
println("Polar day")
case PolarNight =>
println("Polar night")
}
# publish cross-compiled versions
sbt +publish