Crates.io | praytime-rs |
lib.rs | praytime-rs |
version | 1.0.1 |
created_at | 2025-09-14 20:05:35.702548+00 |
updated_at | 2025-09-14 21:41:40.150933+00 |
description | Prayer Times Calculator - A Rust implementation of PrayTimes.org library |
homepage | |
repository | https://gitlab.com/GwNih/praytime-rs |
max_upload_size | |
id | 1839094 |
size | 62,860 |
A Rust implementation of the PrayTimes.org library for calculating Islamic prayer times. This crate provides accurate prayer time calculations based on astronomical formulas and supports multiple calculation methods used around the world.
Add this to your Cargo.toml
:
[dependencies]
praytime-rs = "1.0.0"
use praytime_rs::PrayTime;
let mut praytime = PrayTime::new("ISNA");
praytime.location(43.6532, -79.3832) // Toronto coordinates
.timezone("America/Toronto");
let times = praytime.get_times(None);
println!("Fajr: {}", times.fajr);
println!("Dhuhr: {}", times.dhuhr);
println!("Asr: {}", times.asr);
println!("Maghrib: {}", times.maghrib);
println!("Isha: {}", times.isha);
Method | Description | Fajr Angle | Isha Angle/Time |
---|---|---|---|
ISNA | Islamic Society of North America | 15° | 15° |
MWL | Muslim World League | 18° | 17° |
Egypt | Egyptian General Authority of Survey | 19.5° | 17.5° |
Makkah | Umm Al-Qura University, Makkah | 18.5° | 90 min |
Karachi | University of Islamic Sciences, Karachi | 18° | 18° |
Tehran | Institute of Geophysics, University of Tehran | 17.7° | 4.5° + Jafari |
Jafari | Shia Ithna-Ashari (Jafari) | 16° | 4° + Jafari |
France | France | 12° | 12° |
Russia | Russia | 16° | 15° |
Singapore | Singapore | 20° | 18° |
use praytime_rs::{PrayTime, TimeFormat};
use chrono::NaiveDate;
let mut praytime = PrayTime::new("ISNA");
praytime.location(21.4225, 39.8262) // Makkah coordinates
.timezone("Asia/Riyadh")
.format(TimeFormat::Hour12);
let date = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
let times = praytime.get_times(Some(date));
let mut praytime = PrayTime::new("MWL");
praytime.location(40.7128, -74.0060) // New York coordinates
.utc_offset(-300); // -5 hours in minutes
use praytime_rs::{PrayTime, AsrMethod};
let mut praytime = PrayTime::new("ISNA");
praytime.location(43.6532, -79.3832)
.asr_method(AsrMethod::Hanafi);
use praytime_rs::{PrayTime, HighLatitudeRule};
let mut praytime = PrayTime::new("ISNA");
praytime.location(59.3293, 18.0686) // Stockholm coordinates
.high_latitude_rule(HighLatitudeRule::NightMiddle);
use praytime_rs::TuneAdjustments;
// Add 2 minutes to Fajr, subtract 1 minute from Isha
praytime.tune_with(TuneAdjustments {
fajr: 2.0,
sunrise: 0.0,
dhuhr: 0.0,
asr: 0.0,
sunset: 0.0,
maghrib: 0.0,
isha: -1.0,
midnight: 0.0,
});
use praytime_rs::{TimeFormat, RoundingMethod};
praytime.format(TimeFormat::Hour12)
.rounding(RoundingMethod::Nearest);
PrayTime::new(method: &str)
- Create new instance with calculation methodlocation(lat: f64, lng: f64)
- Set coordinatestimezone(tz: &str)
- Set timezone (e.g., "America/Toronto")utc_offset(minutes: i32)
- Set UTC offset in minutesget_times(date: Option<NaiveDate>)
- Calculate prayer timesformat(format: TimeFormat)
- Set time formatrounding(method: RoundingMethod)
- Set rounding methodasr_method(method: AsrMethod)
- Set ASR calculation methodhigh_latitude_rule(rule: HighLatitudeRule)
- Set high latitude adjustmenttune_with(TuneAdjustments)
- Fine-tune individual prayer timesHour24
- 24-hour format (default)Hour12
- 12-hour with AM/PMHour12NoSuffix
- 12-hour without AM/PMTimestamp
- Unix timestampNearest
- Round to nearest minute (default)Up
- Round upDown
- Round downNone
- No roundingStandard
- Shafi, Maliki, Hanbali (default)Hanafi
- Hanafi schoolNightMiddle
- Middle of night (default)OneSeventh
- 1/7th of nightAngleBased
- Angle-based methodNone
- No adjustmentRun the example to see the library in action:
cargo run --example basic_usage
Run the test suite:
cargo test
This project is licensed under the Code Waqf License (Lisensi Wakaf Kode) - a custom Islamic license that permits free use while prohibiting usage for activities that contradict Islamic principles.
The Code Waqf License template is available at: https://gitlab.com/GwNih/templat-lisensi-wakaf
See the LICENSE file for the complete license text.
Contributions are welcome! Please feel free to submit a Pull Request.