#sunrise #sunset #times #calculator #calendar #libm #calculating

yanked sunrise-next

Sunrise and sunset calculator

1.2.5 Mar 9, 2025
1.2.4 Dec 7, 2024
1.2.3 Jun 24, 2023

#2 in #calculating

Download history 2294/week @ 2024-12-24 650/week @ 2024-12-31 469/week @ 2025-01-07 335/week @ 2025-01-14 454/week @ 2025-01-21 618/week @ 2025-01-28 224/week @ 2025-02-04 733/week @ 2025-02-11 719/week @ 2025-02-18 762/week @ 2025-02-25 276/week @ 2025-03-04 215/week @ 2025-03-11 185/week @ 2025-03-18 96/week @ 2025-03-25 86/week @ 2025-04-01 9/week @ 2025-04-08

396 downloads per month

MIT license

33KB
438 lines

sunrise

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

⚠️ This repository is deprecated as all changes have been ported upstream, please use 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-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