/** * Get a pretty formatted duration for the given number of seconds. (e.g. "4 days, 2 hours, 30 minutes") * * @param numSecs the number of seconds in the duration * @param secondsPerDay the number of seconds in a "day" * @param secondsPerWeek the number of seconds in a "week" * @param resourceBundle the bundle containing translations for the strings used in the pretty string (e.g. "days") * @return the formatted pretty duration */ public static String getDurationPrettySeconds(long numSecs, long secondsPerDay, long secondsPerWeek, ResourceBundle resourceBundle) { return getDurationPrettySeconds(numSecs, secondsPerDay, secondsPerWeek, resourceBundle, false); }
/** * Get a pretty formatted duration for the given number of seconds. (e.g. "4 days, 2 hours, 30 minutes") * * @param numSecs the number of seconds in the duration * @param secondsPerDay the number of seconds in a "day" * @param secondsPerWeek the number of seconds in a "week" * @param resourceBundle the bundle containing translations for the strings used in the pretty string (e.g. "days") * @param secondsDuration if false only display down to the minute even if there are some seconds, else display seconds * @return the formatted pretty duration */ private static String getDurationPrettySeconds(long numSecs, long secondsPerDay, long secondsPerWeek, ResourceBundle resourceBundle, boolean secondsDuration) { // use perWeek to calculate perYear because that already has "days per week" already figured in. if a week only had 3 days, for instance then // doing secondsPerDay * 365 would overestimate how much we can get done in a year. final long secondsPerYear = secondsPerWeek * 52; return getDurationPrettySeconds(numSecs, secondsPerYear, secondsPerDay, secondsPerWeek, resourceBundle, secondsDuration); }
@VisibleForTesting String getDurationPrettySeconds(final Long duration, final ResourceBundle resourceBundle, final long secondsPerDay, final long secondsPerWeek) { return DateUtils.getDurationPrettySeconds(duration, secondsPerDay, secondsPerWeek, resourceBundle); }
private static String getDurationPrettySeconds(long numSecs, long secondsPerDay, long secondsPerWeek, ResourceBundle resourceBundle, boolean secondsDuration) { return getDurationPrettySeconds(numSecs, Duration.YEAR.getSeconds(), secondsPerDay, secondsPerWeek, resourceBundle, secondsDuration); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute, 16 seconds'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param hoursPerDay the hours in a day * @param daysPerWeek the number of days in a week * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using second resolution */ public static String getDurationPrettySecondsResolution(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle) { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, true); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute, 16 seconds'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param hoursPerDay the hours in a day * @param daysPerWeek the number of days in a week * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using second resolution */ public static String getDurationPrettySecondsResolution(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle) { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, true); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will * only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param hoursPerDay the hours in a day * @param daysPerWeek the number of days in a week * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using minute resolution */ public static String getDurationPretty(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle) { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, false); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will * only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param hoursPerDay the hours in a day * @param daysPerWeek the number of days in a week * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using minute resolution */ public static String getDurationPretty(long numSecs, int hoursPerDay, int daysPerWeek, ResourceBundle resourceBundle) { long secondsInDay = hoursPerDay * Duration.HOUR.getSeconds(); long secondsPerWeek = daysPerWeek * secondsInDay; return getDurationPrettySeconds(numSecs, secondsInDay, secondsPerWeek, resourceBundle, false); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute, 16 seconds'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using second resolution */ public static String getDurationPrettySecondsResolution(long numSecs, ResourceBundle resourceBundle) { return getDurationPrettySeconds(numSecs, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), resourceBundle, true); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will * only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using minute resolution */ public static String getDurationPretty(long numSecs, ResourceBundle resourceBundle) { return getDurationPrettySeconds(numSecs, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), resourceBundle, false); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute, 16 seconds'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using second resolution */ public static String getDurationPrettySecondsResolution(long numSecs, ResourceBundle resourceBundle) { return getDurationPrettySeconds(numSecs, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), resourceBundle, true); }
/** * Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will * only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds. * <p/> * So for example <code>76</code> becomes <code>'1 minute'</code>, while <code>42</code> becomes <code>'42 seconds'</code> * * @param numSecs the number of seconds in the duration * @param resourceBundle a resouce bundle for i18n * @return a string in readable pretty duration format, using minute resolution */ public static String getDurationPretty(long numSecs, ResourceBundle resourceBundle) { return getDurationPrettySeconds(numSecs, Duration.DAY.getSeconds(), Duration.WEEK.getSeconds(), resourceBundle, false); }