summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-05-28 01:17:59 +0100
committerCarl Hetherington <cth@carlh.net>2018-05-28 01:17:59 +0100
commit9d904847726295852b78b0029939d0f848793d06 (patch)
tree4a985ec00ecb7558060843d4a3f23d64118e1269 /src/lib
parent1f12c554e58f13fbed38313279c1c5418e0721ca (diff)
Fix seconds_to_approximate_hms sometimes saying things like 1h60m (#1314).
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util.cc39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 3eb5ee30e..7da5f9f90 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -157,18 +157,27 @@ seconds_to_approximate_hms (int s)
string ap;
- bool const hours = h > 0;
- bool const minutes = h < 6 && m > 0;
- bool const seconds = h == 0 && m < 10 && s > 0;
+ bool hours = h > 0;
+ bool minutes = h < 6 && m > 0;
+ bool seconds = h == 0 && m < 10 && s > 0;
- if (hours) {
- if (m > 30 && !minutes) {
- /// TRANSLATORS: h here is an abbreviation for hours
- ap += locale_convert<string>(h + 1) + _("h");
- } else {
- /// TRANSLATORS: h here is an abbreviation for hours
- ap += locale_convert<string>(h) + _("h");
+ if (m > 30 && !minutes) {
+ /* round up the hours */
+ ++h;
+ }
+ if (s > 30 && !seconds) {
+ /* round up the minutes */
+ ++m;
+ if (m == 60) {
+ m = 0;
+ minutes = false;
+ ++h;
}
+ }
+
+ if (hours) {
+ /// TRANSLATORS: h here is an abbreviation for hours
+ ap += locale_convert<string>(h) + _("h");
if (minutes || seconds) {
ap += N_(" ");
@@ -176,14 +185,8 @@ seconds_to_approximate_hms (int s)
}
if (minutes) {
- /* Minutes */
- if (s > 30 && !seconds) {
- /// TRANSLATORS: m here is an abbreviation for minutes
- ap += locale_convert<string>(m + 1) + _("m");
- } else {
- /// TRANSLATORS: m here is an abbreviation for minutes
- ap += locale_convert<string>(m) + _("m");
- }
+ /// TRANSLATORS: m here is an abbreviation for minutes
+ ap += locale_convert<string>(m) + _("m");
if (seconds) {
ap += N_(" ");