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"