Skip to main content

prayer_clock/
prayer-clock.rs

1use std::io::{Write, stdout};
2use std::{thread, time::Duration};
3
4use chrono::Local;
5use mawaqit::prelude::*;
6
7fn main() {
8    let coords = Coordinates::new(50.85, 4.35);
9    let params = Configuration::with(Method::MuslimWorldLeague, Madhab::Shafi);
10
11    loop {
12        let today = Local::now().date_naive();
13        let prayers = PrayerSchedule::new()
14            .on(today)
15            .for_location(coords)
16            .with_configuration(params)
17            .calculate()
18            .expect("prayer times calculation failed");
19
20        let current = prayers.current();
21        let next = prayers.next();
22        let (hours, minutes) = prayers.time_remaining();
23        let next_local = prayers.time(next).with_timezone(&Local);
24        let current_time = prayers.current_prayer_time().with_timezone(&Local);
25
26        print!(
27            "\rCurrent: {current:<10?} (since {time:<8})  \
28             Next: {next:<12?} at {next_time:<8}  \
29             Remaining: {hours}h {minutes:02}m   ",
30            time = current_time.format("%H:%M"),
31            next_time = next_local.format("%H:%M"),
32        );
33        stdout().flush().expect("flush failed");
34
35        thread::sleep(Duration::from_secs(1));
36    }
37}