Skip to content

Commit

Permalink
fix: round the prayer times to the nearest minute
Browse files Browse the repository at this point in the history
  • Loading branch information
Brikaa authored Dec 13, 2024
1 parent 72708bf commit 024d628
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ impl std::convert::From<islam::error::Error> for Error {
}
}

impl std::convert::From<islam::jiff::Error> for Error {
fn from(err: islam::jiff::Error) -> Self {
Self::Internal(err.to_string())
}
}

impl std::convert::From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Internal(err.to_string())
Expand Down
13 changes: 7 additions & 6 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use owo_colors::{OwoColorize, Stream::Stdout};

use islam::jiff::civil;
use islam::jiff::{civil, Unit};
use islam::salah::PrayerTimes;

use crate::{
Expand Down Expand Up @@ -33,7 +33,7 @@ impl Printer {
let prayers = self.prayers;

let fmt_output = |name: &str, time: civil::DateTime| -> Result<String, crate::Error> {
Ok(format!("{}: {}", name, self.format_time(time)))
Ok(format!("{}: {}", name, self.format_time(time)?))
};

Self::print(&fmt_output("Fajr", prayers.fajr)?);
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Printer {
let prayers = self.prayers;
let prayer = prayers.next();
let time = prayers.time(prayer);
let time = self.format_time(time);
let time = self.format_time(time)?;

// default
let mut prayer_fmt = format!("{} ({})", prayer.name(), time);
Expand All @@ -118,11 +118,12 @@ impl Printer {
Self::print(&prayer_fmt);
Ok(())
}
fn format_time(&self, time: civil::DateTime) -> String {
match &self.config.time_format {
fn format_time(&self, time: civil::DateTime) -> Result<String, crate::Error> {
let time = time.round(Unit::Minute)?;
Ok(match &self.config.time_format {
TimeFormat::H24 => time.strftime("%H:%M").to_string(),
TimeFormat::H12 => time.strftime("%I:%M %p").to_string(),
}
})
}
fn print(prayer_fmt: &str) {
writeln!(io::stdout(), "{}", prayer_fmt).ok();
Expand Down

0 comments on commit 024d628

Please sign in to comment.