/** * Gets the short {@link PeriodFormatter}. * * @param aContentLocale The content locale for which the formatter is requested. May not be * <code>null</code>. * @return the formatter */ @Nonnull public static PeriodFormatter getFormatterShort(@Nonnull final Locale aContentLocale) { final String sSepFront = EText.LONG_SEPARATOR_FRONT.getDisplayText(aContentLocale); final String sSepFinal = EText.LONG_SEPARATOR_LAST.getDisplayText(aContentLocale); final String[] aVariants = _getSeparatorVariants(aContentLocale); return new PeriodFormatterBuilder() .appendYears() .appendSuffix(EText.SHORT_YEAR.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMonths() .appendSuffix(EText.SHORT_MONTH.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendWeeks() .appendSuffix(EText.SHORT_WEEK.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendDays() .appendSuffix(EText.SHORT_DAY.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendHours() .appendSuffix(EText.SHORT_HOUR.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMinutes() .appendSuffix(EText.SHORT_MINUTE.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendSeconds() .appendSuffix(EText.SHORT_SECOND.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMillis() .appendSuffix(EText.SHORT_MILLISECOND.getDisplayText(aContentLocale)) .toFormatter(); }
@Nonnull private static String[] _getSeparatorVariants(final Locale aContentLocale) { final String sSepFront = EText.LONG_SEPARATOR_FRONT.getDisplayText(aContentLocale); final String sSepFinal = EText.LONG_SEPARATOR_LAST.getDisplayText(aContentLocale); return new String[] { " ", sSepFront.trim(), sSepFront.trim() + sSepFinal.trim() + " ", sSepFront.trim() + sSepFinal }; }
@Nonnull public static PeriodFormatter getFormatterLong(@Nonnull final Locale aContentLocale) { final String sSepFront = EText.LONG_SEPARATOR_FRONT.getDisplayText(aContentLocale); final String sSepFinal = EText.LONG_SEPARATOR_LAST.getDisplayText(aContentLocale); final String[] aVariants = _getSeparatorVariants(aContentLocale); return new PeriodFormatterBuilder() .appendYears() .appendSuffix( EText.LONG_YEAR_SINGULAR.getDisplayText(aContentLocale), EText.LONG_YEAR_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMonths() .appendSuffix( EText.LONG_MONTH_SINGULAR.getDisplayText(aContentLocale), EText.LONG_MONTH_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendWeeks() .appendSuffix( EText.LONG_WEEK_SINGULAR.getDisplayText(aContentLocale), EText.LONG_WEEK_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendDays() .appendSuffix( EText.LONG_DAY_SINGULAR.getDisplayText(aContentLocale), EText.LONG_DAY_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendHours() .appendSuffix( EText.LONG_HOUR_SINGULAR.getDisplayText(aContentLocale), EText.LONG_HOUR_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMinutes() .appendSuffix( EText.LONG_MINUTE_SINGULAR.getDisplayText(aContentLocale), EText.LONG_MINUTE_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendSeconds() .appendSuffix( EText.LONG_SECOND_SINGULAR.getDisplayText(aContentLocale), EText.LONG_SECOND_PLURAL.getDisplayText(aContentLocale)) .appendSeparator(sSepFront, sSepFinal, aVariants) .appendMillis() .appendSuffix( EText.LONG_MILLISECOND_SINGULAR.getDisplayText(aContentLocale), EText.LONG_MILLISECOND_PLURAL.getDisplayText(aContentLocale)) .toFormatter(); }