8 stable releases

1.2.4 Dec 7, 2024
1.2.3 Jun 24, 2023
1.2.2 Jun 17, 2023
1.1.0 Jun 17, 2023
1.0.1 Jun 17, 2023

#58 in Date and time

Download history 26/week @ 2024-10-28 222/week @ 2024-11-11 514/week @ 2024-11-18 461/week @ 2024-11-25 568/week @ 2024-12-02 546/week @ 2024-12-09 606/week @ 2024-12-16 2204/week @ 2024-12-23 752/week @ 2024-12-30 487/week @ 2025-01-06 328/week @ 2025-01-13 480/week @ 2025-01-20 371/week @ 2025-01-27 490/week @ 2025-02-03 842/week @ 2025-02-10

2,236 downloads per month
Used in opening-hours

MIT license

33KB
438 lines

sunrise

This is a fork of nathan-osman's crate to test new features.

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-next = "1.3"

You can use the sunrise_sunset function to perform the calculation:

// Calculate times for January 1, 2016 in Toronto
let (sunrise, sunset) = sunrise_next::sunrise_sunset(43.6532, -79.3832, 2016, 1, 1);

If you need more refined control, you can use the SolarDay struct:

use sunrise_next::{sunrise_sunset, SolarDay, SolarEvent, DawnType};

let dawn = SolarDay::new(43.6532, -79.3832, 2016, 1, 1)
    .with_altitude(54.)
    .event_time(SolarEvent::Dawn(DawnType::Civil));

Dependencies

~1–1.3MB
~20K SLoC