shaum_types/
prayer.rs

1//! Prayer time calculation parameters.
2
3use serde::{Serialize, Deserialize};
4
5/// Prayer time calculation parameters.
6///
7/// Controls angles and buffers used for prayer time calculations.
8#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
9pub struct PrayerParams {
10    /// Sun altitude angle for Fajr (degrees below horizon). Default: -20.0 (MABIMS/Indonesia)
11    pub fajr_angle: f64,
12    /// Minutes to subtract from Fajr for Imsak. Default: 10
13    pub imsak_buffer_minutes: i64,
14    /// Safety margin (Ihtiyat) added to all prayer times. Default: 2 minutes
15    pub ihtiyat_minutes: i64,
16    /// Seconds to round prayer times to. Default: 60 (round to next minute)
17    pub rounding_granularity_seconds: i64,
18}
19
20impl Default for PrayerParams {
21    fn default() -> Self {
22        Self {
23            fajr_angle: -20.0,
24            imsak_buffer_minutes: 10,
25            ihtiyat_minutes: 2,
26            rounding_granularity_seconds: 60,
27        }
28    }
29}
30
31impl PrayerParams {
32    /// Creates new prayer parameters with defaults for Ihtiyat (2m) and rounding (60s).
33    pub fn new(fajr_angle: f64, imsak_buffer_minutes: i64) -> Self {
34        Self { 
35            fajr_angle, 
36            imsak_buffer_minutes,
37            ihtiyat_minutes: 2,
38            rounding_granularity_seconds: 60,
39        }
40    }
41    
42    /// Set Ihtiyat (safety margin) in minutes.
43    pub fn with_ihtiyat(mut self, minutes: i64) -> Self {
44        self.ihtiyat_minutes = minutes;
45        self
46    }
47    
48    /// Set rounding granularity in seconds.
49    pub fn with_rounding(mut self, seconds: i64) -> Self {
50        self.rounding_granularity_seconds = seconds;
51        self
52    }
53
54    /// MABIMS/Indonesia standard (-20°, 10 min, +2 min Ihtiyat).
55    pub fn mabims() -> Self { Self::default() }
56
57    /// Egyptian General Authority (-19.5°, 10 min).
58    pub fn egyptian() -> Self {
59        Self { fajr_angle: -19.5, imsak_buffer_minutes: 10, ihtiyat_minutes: 2, rounding_granularity_seconds: 60 }
60    }
61
62    /// Muslim World League (-18°, 10 min).
63    pub fn mwl() -> Self {
64        Self { fajr_angle: -18.0, imsak_buffer_minutes: 10, ihtiyat_minutes: 2, rounding_granularity_seconds: 60 }
65    }
66
67    /// ISNA (North America) standard (-15°, 10 min).
68    pub fn isna() -> Self {
69        Self { fajr_angle: -15.0, imsak_buffer_minutes: 10, ihtiyat_minutes: 2, rounding_granularity_seconds: 60 }
70    }
71
72    /// Umm Al-Qura (Saudi Arabia) standard (-18.5°, 10 min).
73    pub fn umm_al_qura() -> Self {
74        Self { fajr_angle: -18.5, imsak_buffer_minutes: 10, ihtiyat_minutes: 2, rounding_granularity_seconds: 60 }
75    }
76}