From b1a192b384b84d33967b72d212ecbf462d1cfee3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 25 Feb 2020 13:21:26 +1000 Subject: [PATCH] cap answer buttons to 1 decimal place we can switch to NUMBER() instead in the future, but will need to update all the translations at the same time --- pylib/tests/test_schedv1.py | 2 +- pylib/tests/test_schedv2.py | 2 +- rslib/src/sched/timespan.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index edff07beb..d59264997 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -516,7 +516,7 @@ def test_nextIvl(): assert ni(c, 3) == 21600000 # (* 100 2.5 1.3 86400)28080000.0 assert ni(c, 4) == 28080000 - assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.83mo" + assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo" def test_misc(): diff --git a/pylib/tests/test_schedv2.py b/pylib/tests/test_schedv2.py index 2b8f996ac..0df6c2005 100644 --- a/pylib/tests/test_schedv2.py +++ b/pylib/tests/test_schedv2.py @@ -613,7 +613,7 @@ def test_nextIvl(): assert ni(c, 3) == 21600000 # (* 100 2.5 1.3 86400)28080000.0 assert ni(c, 4) == 28080000 - assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.83mo" + assert without_unicode_isolation(d.sched.nextIvlStr(c, 4)) == "10.8mo" def test_bury(): diff --git a/rslib/src/sched/timespan.rs b/rslib/src/sched/timespan.rs index b5725a7b1..9c496811e 100644 --- a/rslib/src/sched/timespan.rs +++ b/rslib/src/sched/timespan.rs @@ -7,8 +7,9 @@ use crate::i18n::{tr_args, FString, I18n}; pub fn answer_button_time(seconds: f32, i18n: &I18n) -> String { let span = Timespan::from_secs(seconds).natural_span(); let amount = match span.unit() { - TimespanUnit::Months | TimespanUnit::Years => span.as_unit(), - // we don't show fractional values except for months/years + // months/years shown with 1 decimal place + TimespanUnit::Months | TimespanUnit::Years => (span.as_unit() * 10.0).round() / 10.0, + // other values shown without decimals _ => span.as_unit().round(), }; let args = tr_args!["amount" => amount];