Crates.io | sun |
lib.rs | sun |
version | 0.3.1 |
source | src |
created_at | 2015-07-16 23:52:33.875491 |
updated_at | 2024-10-18 01:59:28.687996 |
description | Calculate the position of the sun. |
homepage | https://github.com/flosse/rust-sun |
repository | https://github.com/flosse/rust-sun |
max_upload_size | |
id | 2617 |
size | 13,521 |
A Rust port of the JS library suncalc.
Add the following to your Cargo.toml
[dependencies]
sun = "0.3"
pub fn main() {
let unixtime = 1_362_441_600_000.0;
let lat = 48.0;
let lon = 9.0;
let pos = sun::pos(unixtime,lat,lon);
let az = pos.azimuth.to_degrees();
let alt = pos.altitude.to_degrees();
println!("The position of the sun is {az}/{alt}");
let time_ms = sun::time_at_phase(unixtime, sun::SunPhase::Sunrise, lat, lon, 0.0);
println!("Sunrise is at {time_ms}");
}