Skip to main content

basics/
basics.rs

1use jiff::{civil, tz::TimeZone};
2use rust_zmanim::prelude::*;
3
4fn main() {
5    let date = civil::date(2025, 7, 29);
6
7    // your location here
8    let beit_meir = GeoLocation::new(
9        31.7975,
10        35.0345,
11        526.0,
12        TimeZone::get("Asia/Jerusalem").unwrap(),
13    )
14    .unwrap();
15
16    // the zmanim_calculator provides some basic building blocks of zmanim
17    if let Some(sunrise) = zmanim_calculator::hanetz(date, &beit_meir, false) {
18        println!("Sunrise: {}", sunrise.strftime("%Y-%m-%d %H:%M:%S %Z"));
19    }
20
21    // zmanim_calculator also lets you make any custom tzeis, alos, etc using
22    // ZmanOffset. these may be based on degrees, fixed time, or shaos zmaniyos
23    if let Some(tzeis_degrees) =
24        zmanim_calculator::tzeis(date, &beit_meir, false, &ZmanOffset::Degrees(6.13))
25    {
26        println!(
27            "Tzeis (6.13 deg): {}",
28            tzeis_degrees.strftime("%Y-%m-%d %H:%M:%S %Z")
29        );
30    }
31
32    // there is also a ComplexZmanimCalendar struct which stores the date and
33    // location, convenient for getting many zmanim for the same point in 4D space.
34    // It also has many common zmanim pre-made
35    let czc = ComplexZmanimCalendar::new(beit_meir, date, UseElevation::No);
36
37    if let Some(alos120) = czc.alos_120_minutes() {
38        println!(
39            "Alos (120 min): {}",
40            alos120.strftime("%Y-%m-%d %H:%M:%S %Z")
41        );
42    }
43
44    if let Some(sz18) = czc.shaah_zmanis_mga_18_degrees() {
45        println!("Shaah zmanis (MGA 18 deg): {sz18:#}");
46    }
47
48    // the calculations will return None if the specified solar event will not
49    // occur
50    let north_pole = GeoLocation::new(90.0, 0.0, 0.0, TimeZone::UTC).unwrap();
51    let polar_sunset = zmanim_calculator::shkia(date, &north_pole, false);
52    println!("Sunset at the North Pole in July: {polar_sunset:?}");
53}