From 1cd0177f878b43168b3477e0fea1f1150ec9b46e Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 25 Oct 2011 21:29:49 +0000 Subject: [PATCH] handle negative durations better --- core/java/src/net/i2p/data/DataHelper.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java index cbb7e615e..1b147ee29 100644 --- a/core/java/src/net/i2p/data/DataHelper.java +++ b/core/java/src/net/i2p/data/DataHelper.java @@ -1242,9 +1242,10 @@ public class DataHelper { */ public static String formatDuration2(long ms) { String t; + long ams = ms >= 0 ? ms : 0 - ms; if (ms == 0) { return "0"; - } else if (ms < 3 * 1000) { + } else if (ams < 3 * 1000) { // NOTE TO TRANSLATORS: Feel free to translate all these as you see fit, there are several options... // spaces or not, '.' or not, plural or not. Try not to make it too long, it is used in // a lot of tables. @@ -1254,22 +1255,22 @@ public class DataHelper { // If you want the digit separator in your locale, translate as {0}. // alternates: msec, msecs t = ngettext("1 ms", "{0,number,####} ms", (int) ms); - } else if (ms < 2 * 60 * 1000) { + } else if (ams < 2 * 60 * 1000) { // seconds // Note to translators: quantity will always be greater than one. // alternates: secs, sec. 'seconds' is probably too long. t = ngettext("1 sec", "{0} sec", (int) (ms / 1000)); - } else if (ms < 120 * 60 * 1000) { + } else if (ams < 120 * 60 * 1000) { // minutes // Note to translators: quantity will always be greater than one. // alternates: mins, min. 'minutes' is probably too long. t = ngettext("1 min", "{0} min", (int) (ms / (60 * 1000))); - } else if (ms < 2 * 24 * 60 * 60 * 1000) { + } else if (ams < 2 * 24 * 60 * 60 * 1000) { // hours // Note to translators: quantity will always be greater than one. // alternates: hrs, hr., hrs. t = ngettext("1 hour", "{0} hours", (int) (ms / (60 * 60 * 1000))); - } else if (ms > 1000l * 24l * 60l * 60l * 1000l) { + } else if (ams > 1000l * 24l * 60l * 60l * 1000l) { return _("n/a"); } else { // days