5 stable releases

Uses new Rust 2024

new 1.2.1 Mar 12, 2025
1.2.0 Mar 9, 2025
1.1.0 Mar 9, 2025
1.0.1 Jun 21, 2023
1.0.0 Dec 15, 2018

#25 in Date and time

Download history 1161/week @ 2024-11-24 1587/week @ 2024-12-01 1618/week @ 2024-12-08 2329/week @ 2024-12-15 1545/week @ 2024-12-22 1875/week @ 2024-12-29 3181/week @ 2025-01-05 3278/week @ 2025-01-12 3674/week @ 2025-01-19 2290/week @ 2025-01-26 2983/week @ 2025-02-02 84857/week @ 2025-02-09 80954/week @ 2025-02-16 102063/week @ 2025-02-23 116323/week @ 2025-03-02 100110/week @ 2025-03-09

406,229 downloads per month
Used in 8 crates

MIT license

35KB
491 lines

sunrise

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

You can enable the no-std feature if you need it to work in such a context, it will rely on libm instead.

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
~20K SLoC