@Test public void getTimeRemainingString() { assertEquals("timeRemaining", ">1 day", MathUtils.GetTimeRemainingString(7 * 24 * 3600 * 1000)); assertEquals("timeRemaining", "0s", MathUtils.GetTimeRemainingString(0)); assertEquals("timeRemaining", "60m 0s", MathUtils.GetTimeRemainingString(3600 * 1000)); }
public static String GetTimeRemainingString(long timeRemainingMillis) { if (timeRemainingMillis < 500) return "0s"; if (timeRemainingMillis > DAY_MILLIS) { return ">1 day"; } if (timeRemainingMillis > HOUR_MILLIS) { long v = timeRemainingMillis; long h = TimeUnit.MILLISECONDS.toHours(v); v -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(v); v -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(v); return String.format(LocaleUtil.getCurrent(), "%dh %dm %ds", h, m, s); } return String.format( LocaleUtil.getCurrent(), "%dm %ds", TimeUnit.MILLISECONDS.toMinutes(timeRemainingMillis), TimeUnit.MILLISECONDS.toSeconds(timeRemainingMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(timeRemainingMillis))); }
MathUtils { public static String GetTimeRemainingString(long timeRemainingMillis) { if (timeRemainingMillis < 500) return "0s"; if (timeRemainingMillis > DAY_MILLIS) { return ">1 day"; } if (timeRemainingMillis > HOUR_MILLIS) { long v = timeRemainingMillis; long h = TimeUnit.MILLISECONDS.toHours(v); v -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(v); v -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(v); return String.format(LocaleUtil.getCurrent(), "%dh %dm %ds", h, m, s); } return String.format( LocaleUtil.getCurrent(), "%dm %ds", TimeUnit.MILLISECONDS.toMinutes(timeRemainingMillis), TimeUnit.MILLISECONDS.toSeconds(timeRemainingMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(timeRemainingMillis))); } }
MathUtils { public static String GetTimeRemainingString(long timeRemainingMillis) { if (timeRemainingMillis < 500) return "0s"; if (timeRemainingMillis > DAY_MILLIS) { return ">1 day"; } if (timeRemainingMillis > HOUR_MILLIS) { long v = timeRemainingMillis; long h = TimeUnit.MILLISECONDS.toHours(v); v -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(v); v -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(v); return String.format(LocaleUtil.getCurrent(), "%dh %dm %ds", h, m, s); } return String.format( LocaleUtil.getCurrent(), "%dm %ds", TimeUnit.MILLISECONDS.toMinutes(timeRemainingMillis), TimeUnit.MILLISECONDS.toSeconds(timeRemainingMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(timeRemainingMillis))); }  }
MathUtils { public static String GetTimeRemainingString(long timeRemainingMillis) { if (timeRemainingMillis < 500) return "0s"; if (timeRemainingMillis > DAY_MILLIS) { return ">1 day"; } if (timeRemainingMillis > HOUR_MILLIS) { long v = timeRemainingMillis; long h = TimeUnit.MILLISECONDS.toHours(v); v -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(v); v -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(v); return String.format(LocaleUtil.getCurrent(), "%dh %dm %ds", h, m, s); } return String.format( LocaleUtil.getCurrent(), "%dm %ds", TimeUnit.MILLISECONDS.toMinutes(timeRemainingMillis), TimeUnit.MILLISECONDS.toSeconds(timeRemainingMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(timeRemainingMillis))); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal); }
MathUtils { public static String GetTimeRemainingString(long timeRemainingMillis) { if (timeRemainingMillis < 500) return "0s"; if (timeRemainingMillis > DAY_MILLIS) { return ">1 day"; } if (timeRemainingMillis > HOUR_MILLIS) { long v = timeRemainingMillis; long h = TimeUnit.MILLISECONDS.toHours(v); v -= TimeUnit.HOURS.toMillis(h); long m = TimeUnit.MILLISECONDS.toMinutes(v); v -= TimeUnit.MINUTES.toMillis(m); long s = TimeUnit.MILLISECONDS.toSeconds(v); return String.format(LocaleUtil.getCurrent(), "%dh %dm %ds", h, m, s); } return String.format( LocaleUtil.getCurrent(), "%dm %ds", TimeUnit.MILLISECONDS.toMinutes(timeRemainingMillis), TimeUnit.MILLISECONDS.toSeconds(timeRemainingMillis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(timeRemainingMillis))); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal);  }