Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@user1823
Copy link
Contributor

@user1823 user1823 commented Aug 4, 2025

@user1823 user1823 marked this pull request as ready for review August 4, 2025 10:30
@Luc-Mcgrady
Copy link
Contributor

Luc-Mcgrady commented Aug 4, 2025

I unknowingly made a duplicate to this pr #4247. Merge whichever one you want.

@Luc-Mcgrady
Copy link
Contributor

maybe remove

       // temporary test of fluent term handling

?

Copy link
Contributor

@Luc-Mcgrady Luc-Mcgrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my pr's way of doing this bit it is cleaner.
This way I can close the duplicate pr.

@dae
Copy link
Member

dae commented Aug 6, 2025

I don't seem to have permission to push into this branch. Please make the following change, based on Luc's suggestions:

commit 5cef2bc5b980ded1682bbc9b425a573f0885b505 (HEAD -> patch-1)
Author: Damien Elmes <[email protected]>
Date:   Wed Aug 6 18:54:05 2025 +1000

    as_provided_unit -> to_unit
    
    Avoids repeating ourselves
    
    https://github.com/ankitects/anki/pull/4242/files#r2252607480

diff --git a/rslib/src/scheduler/timespan.rs b/rslib/src/scheduler/timespan.rs
index 0bc1e0a9a..d3fb3395f 100644
--- a/rslib/src/scheduler/timespan.rs
+++ b/rslib/src/scheduler/timespan.rs
@@ -112,14 +112,10 @@ impl Timespan {
     }
 
     /// Returns the value in the given unit
-    pub fn as_provided_unit(&self, unit: TimespanUnit) -> f32 {
-        match unit {
-            TimespanUnit::Seconds => self.seconds,
-            TimespanUnit::Minutes => self.seconds / MINUTE,
-            TimespanUnit::Hours => self.seconds / HOUR,
-            TimespanUnit::Days => self.seconds / DAY,
-            TimespanUnit::Months => self.seconds / MONTH,
-            TimespanUnit::Years => self.seconds / YEAR,
+    pub fn to_unit(self, unit: TimespanUnit) -> Timespan {
+        Timespan {
+            seconds: self.seconds,
+            unit,
         }
     }
 
diff --git a/rslib/src/stats/today.rs b/rslib/src/stats/today.rs
index f9a677be2..d9680c282 100644
--- a/rslib/src/stats/today.rs
+++ b/rslib/src/stats/today.rs
@@ -10,7 +10,7 @@ use crate::scheduler::timespan::TimespanUnit;
 pub fn studied_today(cards: u32, secs: f32, tr: &I18n) -> String {
     let span = Timespan::from_secs(secs).natural_span();
     let unit = std::cmp::min(span.unit(), TimespanUnit::Minutes);
-    let amount = span.as_provided_unit(unit);
+    let amount = span.to_unit(unit).as_unit();
     let secs_per_card = if cards > 0 {
         secs / (cards as f32)
     } else {

@user1823
Copy link
Contributor Author

user1823 commented Aug 6, 2025

I don't seem to have permission to push into this branch.

That's weird.

image

Anyway, I have made the requested changes. Your suggestion is in between my and Luc's proposed fixes and I like your version more than both of them. Thanks!

@dae
Copy link
Member

dae commented Aug 6, 2025

Thank you both!

@dae dae merged commit 5c6e218 into ankitects:main Aug 6, 2025
1 check passed
@user1823 user1823 deleted the patch-1 branch August 6, 2025 09:35
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

Successfully merging this pull request may close these issues.

4 participants