Bug 397008 - KFormat::formatDuration returns different results with ms large
Summary: KFormat::formatDuration returns different results with ms large
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kcoreaddons
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 5.48.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Michael Pyne
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2018-07-31 09:47 UTC by Safa Alfulaij
Modified: 2018-08-03 16:13 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 5.49.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Safa Alfulaij 2018-07-31 09:47:43 UTC
When you use KFormat::formatDuration with a very large duration, and you pass an option (ex. ShowMilliseconds), the returned value is different than if it was without the option.

Python example (same issue in C++ and QMl):

from PyKF5 import KCoreAddons

INT = 9999999999
mformat = KCoreAddons.KFormat()
print("KFormat.ShowMilliseconds: {}".format(mformat.formatDuration(INT, KCoreAddons.KFormat.ShowMilliseconds)))
print("No options: {}".format(mformat.formatDuration(INT)))

>> KFormat.ShowMilliseconds: 2777:46:39.999
>> No options: 391:41:05
Comment 1 Christoph Feck 2018-07-31 14:55:52 UTC
Currently uses qRound, which returns int, but either should use qRound64 (and double instead of qreal), or just use int arithmetic for rounding, e.g. ((x + 50) / 100) * 100 will round to multiple of 100.

https://cgit.kde.org/kcoreaddons.git/tree/src/lib/util/kformatprivate.cpp#n332
Comment 2 Christoph Feck 2018-08-02 21:43:24 UTC
https://phabricator.kde.org/D14565
Comment 3 Sune Vuorela 2018-08-03 16:01:45 UTC
Git commit ea2779611800e72b516f400abf18aa8ef4abfaec by Sune Vuorela.
Committed on 03/08/2018 at 16:01.
Pushed by sune into branch 'master'.

Fix overflow in rounding code

Summary:
qRound works with int.

Test Plan: add unit tests

Reviewers: cfeck, safaalfulaij

Reviewed By: cfeck, safaalfulaij

Subscribers: kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D14565

M  +11   -0    autotests/kformattest.cpp
M  +2    -2    src/lib/util/kformatprivate.cpp

https://commits.kde.org/kcoreaddons/ea2779611800e72b516f400abf18aa8ef4abfaec