3 releases (breaking)

0.3.1 Oct 18, 2024
0.3.0 Oct 18, 2024
0.2.0 Jul 25, 2015
0.1.0 Jul 16, 2015

#88 in Date and time

Download history 550/week @ 2024-11-21 470/week @ 2024-11-28 566/week @ 2024-12-05 805/week @ 2024-12-12 461/week @ 2024-12-19 91/week @ 2024-12-26 509/week @ 2025-01-02 575/week @ 2025-01-09 469/week @ 2025-01-16 444/week @ 2025-01-23 683/week @ 2025-01-30 551/week @ 2025-02-06 485/week @ 2025-02-13 679/week @ 2025-02-20 868/week @ 2025-02-27 581/week @ 2025-03-06

2,704 downloads per month
Used in 2 crates

MIT license

14KB
238 lines

sun

A Rust port of the JS library suncalc.

Crates.io Docs.rs

Install

Add the following to your Cargo.toml

[dependencies]
sun = "0.3"

Usage

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}");
}

lib.rs:

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);

No runtime deps