From c67fc3e7699dbd6e2a5900f1f2478e130ccf121a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 4 Dec 2017 12:33:23 +1000 Subject: [PATCH] fix time translation patch --- anki/utils.py | 4 ++-- tests/test_utils.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/test_utils.py diff --git a/anki/utils.py b/anki/utils.py index b01fc1b90..2dcb8f4aa 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -69,8 +69,8 @@ def fmtTimeSpan(time, pad=0, point=0, short=False, inTime=False, unit=99): fmt = inTimeTable[type](_pluralCount(time, point)) else: fmt = timeTable[type](_pluralCount(time, point)) - timestr = "%(a)d.%(b)df" % {'a': pad, 'b': point} - return locale.format_string("%" + (fmt % timestr), time) + timestr = "%%%(a)d.%(b)df" % {'a': pad, 'b': point} + return locale.format_string(fmt % timestr, time) def optimalPeriod(time, point, unit): if abs(time) < 60 or unit < 1: diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 000000000..96d787a83 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,7 @@ +# coding: utf-8 + +from anki.utils import fmtTimeSpan + +def test_fmtTimeSpan(): + assert fmtTimeSpan(5) == "5 seconds" + assert fmtTimeSpan(5, inTime=True) == "in 5 seconds"