Skip to content

Commit

Permalink
Fixing the minute overflow value due to rounding up
Browse files Browse the repository at this point in the history
This was causing chrono crate to panic because the value of the 60 minutes is invalid. The valid minute values are 0 to 59 for minutes.

Closes #14
  • Loading branch information
insha committed Apr 21, 2024
1 parent 2ad1c79 commit 0b777c3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "salah"
version = "0.7.1"
version = "0.7.5"
authors = ["Farhan Ahmed <[email protected]>"]
edition = "2018"
description = "Islamic prayer time library for Rust"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Add the following to your `Cargo.toml` file under the `[dependencies]` section:

```
[dependencies]
salah = "0.7.1"
salah = "0.7.5"
```

To get prayer times, use the `PrayerSchedule` struct passing in coordinates, date, and calculation parameters.
Expand All @@ -24,7 +24,7 @@ To get prayer times, use the `PrayerSchedule` struct passing in coordinates, dat
use salah::prelude::*;

let new_york_city = Coordinates::new(40.7128, -74.0059);
let date = Utc.ymd(2019, 1, 25);
let date = NaiveDate::from_ymd_opt(2019, 1, 25).expect("Invalid date provided");
let params = Configuration::with(Method::MoonsightingCommittee, Madhab::Hanafi);
let prayers = PrayerSchedule::new()
.on(date)
Expand Down Expand Up @@ -134,7 +134,7 @@ Shafaq is used by the MoonsightingCommittee method to determine what type of twi
### Prayer Schedule

The `PrayerSchedule` struct is a builder for the the `PrayerTimes` struct. Once the `calculate()` method is invoked on it, a `PrayerTime` struct will be initialized and it will contain fields
for all five prayer times, the time for sunrise, and for the Qiyam prayer.
for all five prayer times, the time for sunrise, and for the Qiyam prayer.

The prayer time will be an instance of `DateTime<Utc>` and as such will refer to a fixed point in universal time. To display these times for the local timezone you will need to format them with the appropriate local time zone.

Expand Down
6 changes: 6 additions & 0 deletions src/astronomy/solar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ impl SolarTime {
let adjusted_mins = (calculated_minutes + calculated_seconds / 60.0).round() as u32;
let adjusted_secs: u32 = 0;

let (hour, mins, secs) = if adjusted_mins > 59 {
(adjusted_hour + 1, 0, adjusted_secs)
} else {
(adjusted_hour, adjusted_mins, adjusted_secs)
};

let adjusted = Utc
.with_ymd_and_hms(
adjusted_date.year(),
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,18 @@ mod tests {
Err(_err) => assert!(false),
}
}

#[test]
fn calculate_time_for_kuala_lumpur() {
let location = Coordinates::new(3.12, 101.69);
let date = NaiveDate::from_ymd_opt(2024, 4, 9).expect("Invalid date provided");
let params = Configuration::with(Method::MuslimWorldLeague, Madhab::Shafi);
let result = PrayerSchedule::new()
.on(date)
.for_location(location)
.with_configuration(params)
.calculate();

assert!(result.is_ok());
}
}

0 comments on commit 0b777c3

Please sign in to comment.