pub struct Configuration { /* private fields */ }Expand description
Builder for Parameters.
Implementations§
Source§impl Configuration
impl Configuration
Sourcepub fn new(fajr_angle: f64, isha_angle: f64) -> Configuration
pub fn new(fajr_angle: f64, isha_angle: f64) -> Configuration
Create a Configuration builder with initial Fajr and Isha angles.
Examples found in repository?
4fn times_at(lat: f64, label: &str, date: NaiveDate, original_coords: Coordinates) {
5 let params = Configuration::new(18.0, 17.0)
6 .method(Method::MuslimWorldLeague)
7 .madhab(Madhab::Shafi)
8 .done();
9
10 let ref_coords = Coordinates::new(lat, original_coords.longitude);
11 match PrayerTimes::try_new(date, ref_coords, params) {
12 Ok(t) => println!(
13 "{label:>12} ({lat:.2}°): {:?} {:?} {:?} {:?} {:?} {:?}",
14 t.time(Prayer::Fajr),
15 t.time(Prayer::Sunrise),
16 t.time(Prayer::Dhuhr),
17 t.time(Prayer::Asr),
18 t.time(Prayer::Maghrib),
19 t.time(Prayer::Isha),
20 ),
21 Err(e) => println!("{label:>12} ({lat:.2}°): FAIL ({e})"),
22 }
23}
24
25fn main() {
26 let date = NaiveDate::from_ymd_opt(2026, 7, 5).expect("valid date");
27 let dt: DateTime<Utc> = date.and_hms_opt(0, 0, 0).unwrap().and_utc();
28 let tromso = Coordinates::new(70.0, 20.0);
29
30 // 1. Original 70°N — no fallback
31 times_at(70.0, "Original 70°", date, tromso);
32
33 // 2. NearestLatitude (resolved)
34 let resolved = PolarFallback::NearestLatitude
35 .resolve_latitude(dt, tromso, Madhab::Shafi)
36 .unwrap();
37 times_at(resolved, "NearestLat", date, tromso);
38 println!(" → Resolved latitude: {resolved:.6}°");
39
40 // 3. Reference45 (fixed 45°N)
41 times_at(45.0, "Reference45", date, tromso);
42
43 // 4. Also show at a clean mid-latitude
44 times_at(48.0, "48° fixed", date, tromso);
45
46 // Now show NearestLatitude via the proper API
47 let params = Configuration::new(18.0, 17.0)
48 .method(Method::MuslimWorldLeague)
49 .madhab(Madhab::Shafi)
50 .polar_fallback(PolarFallback::NearestLatitude)
51 .done();
52 let t = PrayerTimes::try_new(date, tromso, params).unwrap();
53 println!("\nNearestLatitude via API:");
54 println!(
55 " {:?} {:?} {:?} {:?} {:?} {:?}",
56 t.time(Prayer::Fajr),
57 t.time(Prayer::Sunrise),
58 t.time(Prayer::Dhuhr),
59 t.time(Prayer::Asr),
60 t.time(Prayer::Maghrib),
61 t.time(Prayer::Isha),
62 );
63
64 // Also for Jan 15 (winter)
65 let winter = NaiveDate::from_ymd_opt(2026, 1, 15).expect("valid date");
66 let wt: DateTime<Utc> = winter.and_hms_opt(0, 0, 0).unwrap().and_utc();
67 println!("\n--- Winter (Jan 15) ---");
68 times_at(70.0, "Original 70°", winter, tromso);
69
70 let winter_resolved = PolarFallback::NearestLatitude
71 .resolve_latitude(wt, tromso, Madhab::Shafi)
72 .unwrap();
73 times_at(winter_resolved, "NearestLat", winter, tromso);
74 println!(" → Resolved latitude: {winter_resolved:.6}°");
75 times_at(45.0, "Reference45", winter, tromso);
76
77 let t2 = PrayerTimes::try_new(winter, tromso, params).unwrap();
78 println!("\nWinter NearestLatitude via API:");
79 println!(
80 " {:?} {:?} {:?} {:?} {:?} {:?}",
81 t2.time(Prayer::Fajr),
82 t2.time(Prayer::Sunrise),
83 t2.time(Prayer::Dhuhr),
84 t2.time(Prayer::Asr),
85 t2.time(Prayer::Maghrib),
86 t2.time(Prayer::Isha),
87 );
88}Sourcepub fn with(method: Method, madhab: Madhab) -> Parameters
pub fn with(method: Method, madhab: Madhab) -> Parameters
Convenience method: build Parameters from a Method and
Madhab in one step, bypassing the builder chain.
Examples found in repository?
4fn main() {
5 let prayers = PrayerSchedule::new()
6 .on(NaiveDate::from_ymd_opt(2026, 6, 21).expect("invalid date"))
7 .for_location(Coordinates::new(50.85, 4.35)) // Brussels
8 .with_configuration(Configuration::with(
9 Method::MuslimWorldLeague,
10 Madhab::Shafi,
11 ))
12 .calculate()
13 .expect("prayer times calculation failed");
14
15 println!("Prayer times for Brussels on 2026-06-21:");
16 for prayer in &[
17 Prayer::Fajr,
18 Prayer::Sunrise,
19 Prayer::Dhuhr,
20 Prayer::Asr,
21 Prayer::Maghrib,
22 Prayer::Isha,
23 ] {
24 let local = prayers.time(*prayer).with_timezone(&Local);
25 println!(" {prayer:>8?} {}", local.format("%H:%M"));
26 }
27}More examples
18fn main() {
19 // Use the builder to configure and compute prayer times.
20 let result = PrayerSchedule::new()
21 .on(NaiveDate::from_ymd_opt(2026, 6, 21).expect("invalid date"))
22 .for_location(Coordinates::new(50.85, 4.35)) // Brussels
23 .with_configuration(Configuration::with(
24 Method::MuslimWorldLeague,
25 Madhab::Shafi,
26 ))
27 .calculate();
28
29 match result {
30 Ok(prayers) => {
31 println!("Brussels — 2026-06-21 (MWL, Shafi):");
32 print_prayers(&prayers);
33 }
34 Err(e) => {
35 eprintln!("Error: {e}");
36 }
37 }
38
39 // The builder returns an error if required fields are missing.
40 let incomplete = PrayerSchedule::new()
41 .on(NaiveDate::from_ymd_opt(2026, 6, 21).expect("invalid date"))
42 .calculate();
43
44 match incomplete {
45 Ok(_) => println!("unexpected success"),
46 Err(e) => println!("\nExpected error: {e}"),
47 }
48}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}Sourcepub fn method(&mut self, method: Method) -> &mut Configuration
pub fn method(&mut self, method: Method) -> &mut Configuration
Set the calculation authority.
Examples found in repository?
4fn times_at(lat: f64, label: &str, date: NaiveDate, original_coords: Coordinates) {
5 let params = Configuration::new(18.0, 17.0)
6 .method(Method::MuslimWorldLeague)
7 .madhab(Madhab::Shafi)
8 .done();
9
10 let ref_coords = Coordinates::new(lat, original_coords.longitude);
11 match PrayerTimes::try_new(date, ref_coords, params) {
12 Ok(t) => println!(
13 "{label:>12} ({lat:.2}°): {:?} {:?} {:?} {:?} {:?} {:?}",
14 t.time(Prayer::Fajr),
15 t.time(Prayer::Sunrise),
16 t.time(Prayer::Dhuhr),
17 t.time(Prayer::Asr),
18 t.time(Prayer::Maghrib),
19 t.time(Prayer::Isha),
20 ),
21 Err(e) => println!("{label:>12} ({lat:.2}°): FAIL ({e})"),
22 }
23}
24
25fn main() {
26 let date = NaiveDate::from_ymd_opt(2026, 7, 5).expect("valid date");
27 let dt: DateTime<Utc> = date.and_hms_opt(0, 0, 0).unwrap().and_utc();
28 let tromso = Coordinates::new(70.0, 20.0);
29
30 // 1. Original 70°N — no fallback
31 times_at(70.0, "Original 70°", date, tromso);
32
33 // 2. NearestLatitude (resolved)
34 let resolved = PolarFallback::NearestLatitude
35 .resolve_latitude(dt, tromso, Madhab::Shafi)
36 .unwrap();
37 times_at(resolved, "NearestLat", date, tromso);
38 println!(" → Resolved latitude: {resolved:.6}°");
39
40 // 3. Reference45 (fixed 45°N)
41 times_at(45.0, "Reference45", date, tromso);
42
43 // 4. Also show at a clean mid-latitude
44 times_at(48.0, "48° fixed", date, tromso);
45
46 // Now show NearestLatitude via the proper API
47 let params = Configuration::new(18.0, 17.0)
48 .method(Method::MuslimWorldLeague)
49 .madhab(Madhab::Shafi)
50 .polar_fallback(PolarFallback::NearestLatitude)
51 .done();
52 let t = PrayerTimes::try_new(date, tromso, params).unwrap();
53 println!("\nNearestLatitude via API:");
54 println!(
55 " {:?} {:?} {:?} {:?} {:?} {:?}",
56 t.time(Prayer::Fajr),
57 t.time(Prayer::Sunrise),
58 t.time(Prayer::Dhuhr),
59 t.time(Prayer::Asr),
60 t.time(Prayer::Maghrib),
61 t.time(Prayer::Isha),
62 );
63
64 // Also for Jan 15 (winter)
65 let winter = NaiveDate::from_ymd_opt(2026, 1, 15).expect("valid date");
66 let wt: DateTime<Utc> = winter.and_hms_opt(0, 0, 0).unwrap().and_utc();
67 println!("\n--- Winter (Jan 15) ---");
68 times_at(70.0, "Original 70°", winter, tromso);
69
70 let winter_resolved = PolarFallback::NearestLatitude
71 .resolve_latitude(wt, tromso, Madhab::Shafi)
72 .unwrap();
73 times_at(winter_resolved, "NearestLat", winter, tromso);
74 println!(" → Resolved latitude: {winter_resolved:.6}°");
75 times_at(45.0, "Reference45", winter, tromso);
76
77 let t2 = PrayerTimes::try_new(winter, tromso, params).unwrap();
78 println!("\nWinter NearestLatitude via API:");
79 println!(
80 " {:?} {:?} {:?} {:?} {:?} {:?}",
81 t2.time(Prayer::Fajr),
82 t2.time(Prayer::Sunrise),
83 t2.time(Prayer::Dhuhr),
84 t2.time(Prayer::Asr),
85 t2.time(Prayer::Maghrib),
86 t2.time(Prayer::Isha),
87 );
88}Sourcepub fn method_adjustments(
&mut self,
method_adjustments: TimeAdjustment,
) -> &mut Configuration
pub fn method_adjustments( &mut self, method_adjustments: TimeAdjustment, ) -> &mut Configuration
Override the method’s built-in time adjustments.
Sourcepub fn high_latitude_rule(
&mut self,
high_latitude_rule: HighLatitudeRule,
) -> &mut Configuration
pub fn high_latitude_rule( &mut self, high_latitude_rule: HighLatitudeRule, ) -> &mut Configuration
Choose the rule for approximating Fajr and Isha at high latitudes.
Sourcepub fn madhab(&mut self, madhab: Madhab) -> &mut Configuration
pub fn madhab(&mut self, madhab: Madhab) -> &mut Configuration
Set the madhab for Asr shadow-length calculation (Shafi or Hanafi).
Examples found in repository?
4fn times_at(lat: f64, label: &str, date: NaiveDate, original_coords: Coordinates) {
5 let params = Configuration::new(18.0, 17.0)
6 .method(Method::MuslimWorldLeague)
7 .madhab(Madhab::Shafi)
8 .done();
9
10 let ref_coords = Coordinates::new(lat, original_coords.longitude);
11 match PrayerTimes::try_new(date, ref_coords, params) {
12 Ok(t) => println!(
13 "{label:>12} ({lat:.2}°): {:?} {:?} {:?} {:?} {:?} {:?}",
14 t.time(Prayer::Fajr),
15 t.time(Prayer::Sunrise),
16 t.time(Prayer::Dhuhr),
17 t.time(Prayer::Asr),
18 t.time(Prayer::Maghrib),
19 t.time(Prayer::Isha),
20 ),
21 Err(e) => println!("{label:>12} ({lat:.2}°): FAIL ({e})"),
22 }
23}
24
25fn main() {
26 let date = NaiveDate::from_ymd_opt(2026, 7, 5).expect("valid date");
27 let dt: DateTime<Utc> = date.and_hms_opt(0, 0, 0).unwrap().and_utc();
28 let tromso = Coordinates::new(70.0, 20.0);
29
30 // 1. Original 70°N — no fallback
31 times_at(70.0, "Original 70°", date, tromso);
32
33 // 2. NearestLatitude (resolved)
34 let resolved = PolarFallback::NearestLatitude
35 .resolve_latitude(dt, tromso, Madhab::Shafi)
36 .unwrap();
37 times_at(resolved, "NearestLat", date, tromso);
38 println!(" → Resolved latitude: {resolved:.6}°");
39
40 // 3. Reference45 (fixed 45°N)
41 times_at(45.0, "Reference45", date, tromso);
42
43 // 4. Also show at a clean mid-latitude
44 times_at(48.0, "48° fixed", date, tromso);
45
46 // Now show NearestLatitude via the proper API
47 let params = Configuration::new(18.0, 17.0)
48 .method(Method::MuslimWorldLeague)
49 .madhab(Madhab::Shafi)
50 .polar_fallback(PolarFallback::NearestLatitude)
51 .done();
52 let t = PrayerTimes::try_new(date, tromso, params).unwrap();
53 println!("\nNearestLatitude via API:");
54 println!(
55 " {:?} {:?} {:?} {:?} {:?} {:?}",
56 t.time(Prayer::Fajr),
57 t.time(Prayer::Sunrise),
58 t.time(Prayer::Dhuhr),
59 t.time(Prayer::Asr),
60 t.time(Prayer::Maghrib),
61 t.time(Prayer::Isha),
62 );
63
64 // Also for Jan 15 (winter)
65 let winter = NaiveDate::from_ymd_opt(2026, 1, 15).expect("valid date");
66 let wt: DateTime<Utc> = winter.and_hms_opt(0, 0, 0).unwrap().and_utc();
67 println!("\n--- Winter (Jan 15) ---");
68 times_at(70.0, "Original 70°", winter, tromso);
69
70 let winter_resolved = PolarFallback::NearestLatitude
71 .resolve_latitude(wt, tromso, Madhab::Shafi)
72 .unwrap();
73 times_at(winter_resolved, "NearestLat", winter, tromso);
74 println!(" → Resolved latitude: {winter_resolved:.6}°");
75 times_at(45.0, "Reference45", winter, tromso);
76
77 let t2 = PrayerTimes::try_new(winter, tromso, params).unwrap();
78 println!("\nWinter NearestLatitude via API:");
79 println!(
80 " {:?} {:?} {:?} {:?} {:?} {:?}",
81 t2.time(Prayer::Fajr),
82 t2.time(Prayer::Sunrise),
83 t2.time(Prayer::Dhuhr),
84 t2.time(Prayer::Asr),
85 t2.time(Prayer::Maghrib),
86 t2.time(Prayer::Isha),
87 );
88}Sourcepub fn polar_fallback(&mut self, fallback: PolarFallback) -> &mut Configuration
pub fn polar_fallback(&mut self, fallback: PolarFallback) -> &mut Configuration
Set the strategy for handling polar day/night latitudes.
Examples found in repository?
25fn main() {
26 let date = NaiveDate::from_ymd_opt(2026, 7, 5).expect("valid date");
27 let dt: DateTime<Utc> = date.and_hms_opt(0, 0, 0).unwrap().and_utc();
28 let tromso = Coordinates::new(70.0, 20.0);
29
30 // 1. Original 70°N — no fallback
31 times_at(70.0, "Original 70°", date, tromso);
32
33 // 2. NearestLatitude (resolved)
34 let resolved = PolarFallback::NearestLatitude
35 .resolve_latitude(dt, tromso, Madhab::Shafi)
36 .unwrap();
37 times_at(resolved, "NearestLat", date, tromso);
38 println!(" → Resolved latitude: {resolved:.6}°");
39
40 // 3. Reference45 (fixed 45°N)
41 times_at(45.0, "Reference45", date, tromso);
42
43 // 4. Also show at a clean mid-latitude
44 times_at(48.0, "48° fixed", date, tromso);
45
46 // Now show NearestLatitude via the proper API
47 let params = Configuration::new(18.0, 17.0)
48 .method(Method::MuslimWorldLeague)
49 .madhab(Madhab::Shafi)
50 .polar_fallback(PolarFallback::NearestLatitude)
51 .done();
52 let t = PrayerTimes::try_new(date, tromso, params).unwrap();
53 println!("\nNearestLatitude via API:");
54 println!(
55 " {:?} {:?} {:?} {:?} {:?} {:?}",
56 t.time(Prayer::Fajr),
57 t.time(Prayer::Sunrise),
58 t.time(Prayer::Dhuhr),
59 t.time(Prayer::Asr),
60 t.time(Prayer::Maghrib),
61 t.time(Prayer::Isha),
62 );
63
64 // Also for Jan 15 (winter)
65 let winter = NaiveDate::from_ymd_opt(2026, 1, 15).expect("valid date");
66 let wt: DateTime<Utc> = winter.and_hms_opt(0, 0, 0).unwrap().and_utc();
67 println!("\n--- Winter (Jan 15) ---");
68 times_at(70.0, "Original 70°", winter, tromso);
69
70 let winter_resolved = PolarFallback::NearestLatitude
71 .resolve_latitude(wt, tromso, Madhab::Shafi)
72 .unwrap();
73 times_at(winter_resolved, "NearestLat", winter, tromso);
74 println!(" → Resolved latitude: {winter_resolved:.6}°");
75 times_at(45.0, "Reference45", winter, tromso);
76
77 let t2 = PrayerTimes::try_new(winter, tromso, params).unwrap();
78 println!("\nWinter NearestLatitude via API:");
79 println!(
80 " {:?} {:?} {:?} {:?} {:?} {:?}",
81 t2.time(Prayer::Fajr),
82 t2.time(Prayer::Sunrise),
83 t2.time(Prayer::Dhuhr),
84 t2.time(Prayer::Asr),
85 t2.time(Prayer::Maghrib),
86 t2.time(Prayer::Isha),
87 );
88}Sourcepub fn isha_interval(&mut self, isha_interval: i32) -> &mut Configuration
pub fn isha_interval(&mut self, isha_interval: i32) -> &mut Configuration
Use a fixed interval (in minutes) from Maghrib for Isha instead of
a twilight angle. Sets isha_angle to 0.
Used by Umm al-Qura (90 min) and Qatar (90 min).
Sourcepub fn maghrib_angle(&mut self, angle: f64) -> &mut Configuration
pub fn maghrib_angle(&mut self, angle: f64) -> &mut Configuration
Set a custom twilight angle for Maghrib (default: 0° — geometric sunset). Used by the Tehran method (4.5°).
Sourcepub fn rounding(&mut self, value: Rounding) -> &mut Configuration
pub fn rounding(&mut self, value: Rounding) -> &mut Configuration
Set the rounding rule for all computed prayer times.
Sourcepub fn shafaq(&mut self, value: Shafaq) -> &mut Configuration
pub fn shafaq(&mut self, value: Shafaq) -> &mut Configuration
Set the twilight phenomenon used by the Moonsighting Committee method for Isha calculation (General, Ahmer, or Abyad).
Sourcepub fn done(&self) -> Parameters
pub fn done(&self) -> Parameters
Finalise the builder and return the Parameters.
Examples found in repository?
4fn times_at(lat: f64, label: &str, date: NaiveDate, original_coords: Coordinates) {
5 let params = Configuration::new(18.0, 17.0)
6 .method(Method::MuslimWorldLeague)
7 .madhab(Madhab::Shafi)
8 .done();
9
10 let ref_coords = Coordinates::new(lat, original_coords.longitude);
11 match PrayerTimes::try_new(date, ref_coords, params) {
12 Ok(t) => println!(
13 "{label:>12} ({lat:.2}°): {:?} {:?} {:?} {:?} {:?} {:?}",
14 t.time(Prayer::Fajr),
15 t.time(Prayer::Sunrise),
16 t.time(Prayer::Dhuhr),
17 t.time(Prayer::Asr),
18 t.time(Prayer::Maghrib),
19 t.time(Prayer::Isha),
20 ),
21 Err(e) => println!("{label:>12} ({lat:.2}°): FAIL ({e})"),
22 }
23}
24
25fn main() {
26 let date = NaiveDate::from_ymd_opt(2026, 7, 5).expect("valid date");
27 let dt: DateTime<Utc> = date.and_hms_opt(0, 0, 0).unwrap().and_utc();
28 let tromso = Coordinates::new(70.0, 20.0);
29
30 // 1. Original 70°N — no fallback
31 times_at(70.0, "Original 70°", date, tromso);
32
33 // 2. NearestLatitude (resolved)
34 let resolved = PolarFallback::NearestLatitude
35 .resolve_latitude(dt, tromso, Madhab::Shafi)
36 .unwrap();
37 times_at(resolved, "NearestLat", date, tromso);
38 println!(" → Resolved latitude: {resolved:.6}°");
39
40 // 3. Reference45 (fixed 45°N)
41 times_at(45.0, "Reference45", date, tromso);
42
43 // 4. Also show at a clean mid-latitude
44 times_at(48.0, "48° fixed", date, tromso);
45
46 // Now show NearestLatitude via the proper API
47 let params = Configuration::new(18.0, 17.0)
48 .method(Method::MuslimWorldLeague)
49 .madhab(Madhab::Shafi)
50 .polar_fallback(PolarFallback::NearestLatitude)
51 .done();
52 let t = PrayerTimes::try_new(date, tromso, params).unwrap();
53 println!("\nNearestLatitude via API:");
54 println!(
55 " {:?} {:?} {:?} {:?} {:?} {:?}",
56 t.time(Prayer::Fajr),
57 t.time(Prayer::Sunrise),
58 t.time(Prayer::Dhuhr),
59 t.time(Prayer::Asr),
60 t.time(Prayer::Maghrib),
61 t.time(Prayer::Isha),
62 );
63
64 // Also for Jan 15 (winter)
65 let winter = NaiveDate::from_ymd_opt(2026, 1, 15).expect("valid date");
66 let wt: DateTime<Utc> = winter.and_hms_opt(0, 0, 0).unwrap().and_utc();
67 println!("\n--- Winter (Jan 15) ---");
68 times_at(70.0, "Original 70°", winter, tromso);
69
70 let winter_resolved = PolarFallback::NearestLatitude
71 .resolve_latitude(wt, tromso, Madhab::Shafi)
72 .unwrap();
73 times_at(winter_resolved, "NearestLat", winter, tromso);
74 println!(" → Resolved latitude: {winter_resolved:.6}°");
75 times_at(45.0, "Reference45", winter, tromso);
76
77 let t2 = PrayerTimes::try_new(winter, tromso, params).unwrap();
78 println!("\nWinter NearestLatitude via API:");
79 println!(
80 " {:?} {:?} {:?} {:?} {:?} {:?}",
81 t2.time(Prayer::Fajr),
82 t2.time(Prayer::Sunrise),
83 t2.time(Prayer::Dhuhr),
84 t2.time(Prayer::Asr),
85 t2.time(Prayer::Maghrib),
86 t2.time(Prayer::Isha),
87 );
88}