#sun #position #sunrise

suncalc

Calculate the position of the sun and sunlight phases

3 unstable releases

0.4.0 Oct 29, 2021
0.3.1 Oct 23, 2021
0.3.0 Oct 23, 2021

#429 in Date and time

Download history 164/week @ 2024-11-16 548/week @ 2024-11-23 711/week @ 2024-11-30 445/week @ 2024-12-07 297/week @ 2024-12-14 811/week @ 2024-12-21 909/week @ 2024-12-28 1082/week @ 2025-01-04 1115/week @ 2025-01-11 1119/week @ 2025-01-18 970/week @ 2025-01-25 883/week @ 2025-02-01 895/week @ 2025-02-08 535/week @ 2025-02-15 95/week @ 2025-02-22 67/week @ 2025-03-01

1,717 downloads per month

MIT license

17KB
344 lines

sun

A rust port of the JS library suncalc, forked from the sun crate.

Features

  • Get sun position at a given time and position
  • Get sun phase times for a given location
  • Moon calculations

Install

Add the following to your Cargo.toml

[dependencies]
suncalc = "0.3"

Usage

pub fn main() {
  let unixtime = suncalc::Timestamp(1362441600000);
  let lat = 48.0;
  let lon = 9.0;
  let pos = suncalc::get_position(unixtime,lat,lon);
  let az  = pos.azimuth.to_degrees();
  let alt = pos.altitude.to_degrees();
  println!("The position of the sun is {}/{}", az, alt);
}

lib.rs:

The sun crate is a library for calculating the position of the sun. It is a port of the JavaScript library suncalc.

Example

let unixtime = suncalc::Timestamp(1362441600000);
let lat = 48.0;
let lon = 9.0;
let moon_pos = suncalc::get_position(unixtime,lat,lon);
let az  = moon_pos.azimuth.to_degrees();
let alt = moon_pos.altitude.to_degrees();
println!("The position of the sun is {}/{}", az, alt);

No runtime deps