public List<TextOption> getTimeTrackingFormats() { try { final BigDecimal hoursPerDay = new BigDecimal(getHoursPerDay()); final BigDecimal daysPerWeek = new BigDecimal(getDaysPerWeek()); final I18nHelper i18nBean = authenticationContext.getI18nHelper(); final String durationPretty = new JiraDurationUtils.PrettyDurationFormatter(hoursPerDay, daysPerWeek, i18nBean).format(SAMPLE_DURATION); final String durationDays = new JiraDurationUtils.DaysDurationFormatter(hoursPerDay, i18nBean).format(SAMPLE_DURATION); final String durationHours = new JiraDurationUtils.HoursDurationFormatter(i18nBean).format(SAMPLE_DURATION); return CollectionBuilder.newBuilder( new TextOption(JiraDurationUtils.FORMAT_PRETTY, getText(JiraDurationUtils.PrettyDurationFormatter.KEY_FORMAT_PRETTY, durationPretty)), new TextOption(JiraDurationUtils.FORMAT_DAYS, getText(JiraDurationUtils.DaysDurationFormatter.KEY_FORMAT_DAYS, durationDays)), new TextOption(JiraDurationUtils.FORMAT_HOURS, getText(JiraDurationUtils.HoursDurationFormatter.KEY_FORMAT_HOURS, durationHours))).asList(); } catch (NumberFormatException ignored) { } catch (ArithmeticException ignored) { } // can be caused by invalid input. It will be caught above in validation return Collections.emptyList(); }
public String shortFormat(final Long duration, final Locale locale) { return format(duration, locale); }
public String shortFormat(Long duration) { return format(duration); }
/** * Converts the given time duration into hours and formats it based on the given user's locale. If the duration * given is a negative number, returns an empty string. * * @param duration time duration to format * @param locale user's locale * @return formatted time duration or an empty string */ public String format(Long duration, Locale locale) { return format(duration, locator.getHelper(locale), TimeFormatWithPrecision.Scale.DEFAULT); }
/** * Converts the given time duration into hours and formats it based on the system locale. If the duration given * is a negative number, returns an empty string. * * @param duration time duration to format * @return formatted time duration or an empty string */ public String format(Long duration) { return format(duration, locator.getHelper(), TimeFormatWithPrecision.Scale.DEFAULT); }