Crates.io | sunrise-sunset-calculator |
lib.rs | sunrise-sunset-calculator |
version | 1.0.1 |
source | src |
created_at | 2021-08-08 01:30:19.721281 |
updated_at | 2023-05-29 00:10:20.96732 |
description | Sunrise sunset calculator for Rust, supports extreme latitudes. |
homepage | https://github.com/jacob-pro/sunrise-sunset-calculator |
repository | https://github.com/jacob-pro/sunrise-sunset-calculator |
max_upload_size | |
id | 432979 |
size | 91,288 |
A crate for computing sunrise and sunset times.
let result = SunriseSunsetParameters::new(timestamp, latitude, longitude).calculate()?;
$ cargo run --example sunrise-sunset-calculator -- lookup --location london
Using timestamp: 1628381118
Using coordinates: 51.5073219, -0.1276474
Visible: false
Sun set at: 2021-08-07 20:37 (+01:00)
Sun rises at: 2021-08-08 05:35 (+01:00)
Internally this uses a port of NREL's Solar Position Algorithm (SPA) to compute the solar elevation / altitude at a given time. Dates between -2000 and 6000 are accepted.
We use the NOAA definition of sunrise/sunset as being at the point which the center of the sun is 0.8333° below the horizon. We then use interval bisection to find the point at which the sun's elevation crosses this boundary.
It will work at all latitudes on Earth, although the step size option controls the shortest day/night lengths that will be detected, which is configured with a reasonable default based on the input latitude.
All my code is LGPL, but the NREL algorithm this bundles has its own separate license, so take this into account.