6 stable releases

Uses new Rust 2024

new 2.0.0 Apr 30, 2025
1.2.1 Mar 12, 2025
1.0.1 Jun 21, 2023
1.0.0 Dec 15, 2018

#29 in Date and time

Download history 3322/week @ 2025-01-11 3664/week @ 2025-01-18 2431/week @ 2025-01-25 2861/week @ 2025-02-01 78300/week @ 2025-02-08 81063/week @ 2025-02-15 99646/week @ 2025-02-22 120070/week @ 2025-03-01 103662/week @ 2025-03-08 81831/week @ 2025-03-15 75014/week @ 2025-03-22 73158/week @ 2025-03-29 59886/week @ 2025-04-05 48590/week @ 2025-04-12 43387/week @ 2025-04-19 40593/week @ 2025-04-26

203,920 downloads per month
Used in 8 crates

MIT license

36KB
515 lines

sunrise

This crate provides a function for calculating sunrise and sunset times using this method.

To work in a no-std environment disable the default features and enable the libm feature.

Usage

In order to perform the calculation, you'll need to provide the following:

  • the date for which you wish to calculate the times
  • the latitude and longitude of the location

Begin by adding this crate to Cargo.toml:

[dependencies]
sunrise = "1.2"

You can use the SolarDay struct to perform computation of an event at a particular place and time:

use chrono::NaiveDate;
use sunrise::{Coordinates, SolarDay, SolarEvent, DawnType};

// January 1, 2016 in Toronto
let date = NaiveDate::from_ymd_opt(2016, 1, 1).unwrap();
let coord = Coordinates::new(43.6532, -79.3832).unwrap();

let dawn = SolarDay::new(coord, date)
    .with_altitude(54.)
    .event_time(SolarEvent::Dawn(DawnType::Civil));

Dependencies

~1–1.3MB
~21K SLoC