Crate sun

Source
Expand description

The sun crate is a library for calculating the position of the sun and sun phases (like sunrise, sunset). It is a port of the JavaScript library suncalc.

§Example

let unixtime = 1_362_441_600_000;
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}");

// calculate time of sunrise
let time_ms = sun::time_at_phase(unixtime, sun::SunPhase::Sunrise, lat, lon, 0.0);
assert_eq!(time_ms, 1_362_463_116_241);

Structs§

Position
Holds the azimuth and altitude angles of the sun position.

Enums§

SunPhase
Sun phases for use with time_at_phase.

Functions§

pos
Calculates the sun position for a given date and latitude/longitude. The angles are calculated as radians.
time_at_phase
Calculates the time for the given SunPhase at a given date, height and Latitude/Longitude. The returned time is the unix time in milliseconds.