Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for fractional days #42

Open
shivangp76 opened this issue Oct 24, 2024 · 2 comments
Open

Support for fractional days #42

shivangp76 opened this issue Oct 24, 2024 · 2 comments

Comments

@shivangp76
Copy link
Contributor

I was wondering if there would by any interest in supporting fractional days.

Chrono's .num_days() does not round the number of days. See this Rust playground.

A possible solution is to implement something like this:

pub trait FractionalDays {
    fn num_fractional_days(&self) -> f64;
    fn fractional_days(fractional_days: f64) -> Self;
}

impl FractionalDays for Duration {
    fn num_fractional_days(&self) -> f64 {
        let seconds_in_a_day = 24.0 * 3600.0;
        f64::from(self.num_seconds() as i32) / seconds_in_a_day
    }

    fn fractional_days(fractional_days: f64) -> Self {
        Duration::seconds((fractional_days * 24. * 60. * 60.).round() as i64)
    }
}
@asukaminato0721
Copy link
Collaborator

seems fixed by #41

@shivangp76
Copy link
Contributor Author

This is more of a general question, throughout the crate. #41 is only for a specific function. For example, could Card.elapsed_days be an f64 instead of an i64? Could the following be changed to utilize something like num_fractional_days() mentioned in the original request?

_ => (now - card.last_review).num_days(),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants