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

#83 in Date and time

Download history 1031/week @ 2024-09-20 990/week @ 2024-09-27 802/week @ 2024-10-04 696/week @ 2024-10-11 1144/week @ 2024-10-18 1136/week @ 2024-10-25 896/week @ 2024-11-01 537/week @ 2024-11-08 708/week @ 2024-11-15 482/week @ 2024-11-22 578/week @ 2024-11-29 505/week @ 2024-12-06 902/week @ 2024-12-13 272/week @ 2024-12-20 113/week @ 2024-12-27 455/week @ 2025-01-03

1,849 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