Example usage for org.joda.time.format PeriodFormat wordBased

List of usage examples for org.joda.time.format PeriodFormat wordBased

Introduction

In this page you can find the example usage for org.joda.time.format PeriodFormat wordBased.

Prototype

public static PeriodFormatter wordBased(Locale locale) 

Source Link

Document

Returns a word based formatter for the specified locale.

Usage

From source file:com.mycollab.core.utils.DateTimeUtils.java

License:Open Source License

public static String getPrettyDurationValue(Date date, Locale locale) {
    Period period = new Period(new LocalDate(date), LocalDate.now());
    PeriodFormatter formatter = PeriodFormat.wordBased(locale);
    return formatter.print(period);
}

From source file:org.kalypso.commons.time.PeriodUtils.java

License:Open Source License

/**
 * Formats a {@link Period} with a default format, using the current default locale.
 *///from  w ww  .j a  v a 2  s.c  o  m
public static String formatDefault(final Period period) {
    if (period == null)
        return StringUtils.EMPTY;

    final PeriodFormatter formatter = PeriodFormat.wordBased(Locale.getDefault());
    return formatter.print(period);
}

From source file:org.sakaiproject.accountvalidator.logic.impl.ValidationLogicImpl.java

License:Educational Community License

private String getFormattedExpirationMinutes() {
    int expirationMinutes = serverConfigurationService.getInt(MAX_PASSWORD_RESET_MINUTES,
            MAX_PASSWORD_RESET_MINUTES_DEFAULT);
    Period period = new Period(expirationMinutes * 60 * 1000);
    PeriodFormatter periodFormatter = PeriodFormat.wordBased(rl.getLocale());
    return periodFormatter.print(period);
}

From source file:org.sakaiproject.accountvalidator.tool.producers.PasswordResetProducer.java

License:Educational Community License

/**
 * Converts some number of minutes into a presentable String'
 * ie for English:/*from www .j a v a2 s .c o  m*/
 * 122 minutes   ->   2 hours 2 minutes
 * 121 minutes   ->   2 hours 1 minute
 * 120 minutes   ->   2 hours
 * 62 minutes   ->   1 hour 2 minutes
 * 61 minutes   ->   1 hour 1 minute
 * 60 minutes   ->   1 hour
 * 2 minutes   ->   2 minutes
 * 1 minutes   ->   1 minute
 * 0 minutes   ->   0 minutes
 * Works with other languages too.
 * @param totalMinutes some number of minutes
 * @return a presentable String representation of totalMinutes
 */
public String getFormattedMinutes(int totalMinutes) {
    // Create a joda time period (takes milliseconds)
    Period period = new Period(totalMinutes * 60 * 1000);
    // format the period for the locale
    /* 
     * Covers English, Danish, Dutch, French, German, Japanese, Portuguese, and Spanish. 
     * To translate into others, see http://joda-time.sourceforge.net/apidocs/org/joda/time/format/PeriodFormat.html#wordBased(java.util.Locale)
     * (ie. put the properties mentioned in http://joda-time.sourceforge.net/apidocs/src-html/org/joda/time/format/PeriodFormat.html#line.94 into the classpath resource bundle)
     */
    PeriodFormatter periodFormatter = PeriodFormat.wordBased(getLocale());
    return periodFormatter.print(period);
}

From source file:org.xwiki.contrib.ratelimiter.internal.DefaultRateLimiterServiceConfiguration.java

License:Open Source License

@Override
public String getFormattedMailInterval() {
    Period period = new Period(getMailInterval());
    PeriodFormatter formatter = PeriodFormat.wordBased(getLocale());
    return formatter.print(period);
}

From source file:org.xwiki.contrib.ratelimiter.script.RateLimiterScriptService.java

License:Open Source License

/**
 * Return as a human readable formatted string the time to wait before a given amount can be consumed by the
 * current user on the current wiki.//from  w ww  .  j a  v  a 2  s.  c o m
 *
 * @param amount the amount that should be consumable.
 * @param locale the locale used to format the result.
 * @return the time to wait as a formatted string.
 */
public String getFormattedWaitingTime(long amount, Locale locale) {
    Period period = new Period(getWaitingTime(amount, TimeUnit.MILLISECONDS));
    PeriodFormatter formatter = PeriodFormat.wordBased(locale);
    return formatter.print(period);
}

From source file:org.xwiki.contrib.ratelimiter.script.RateLimiterScriptService.java

License:Open Source License

/**
 * Return as a human readable formatted string the time to wait before a given amount can be consumed by the
 * current user on the current wiki./*from   w  w w .  j av  a  2  s  .  c o m*/
 *
 * @param consumer the entity consuming.
 * @param consumed the entity being consumed.
 * @param amount the amount that should be consumable.
 * @param locale the locale used to format the result.
 * @return the time to wait as a formatted string.
 */
public String getFormattedWaitingTime(Object consumer, Object consumed, long amount, Locale locale) {
    if (contextualAuthorizationManager.hasAccess(Right.PROGRAM)) {
        Period period = new Period(getWaitingTime(consumer, consumed, amount, TimeUnit.MILLISECONDS));
        PeriodFormatter formatter = PeriodFormat.wordBased(locale);
        return formatter.print(period);
    }
    return null;
}

From source file:ru.anr.base.BaseParent.java

License:Apache License

/**
 * @param startDate/*from w ww . j a  v  a  2  s  .co  m*/
 *            Start date
 * @param endDate
 *            End date
 * @param locale
 *            Locale
 * @return formatted period without seconds
 */
public static String formatPeriodWithoutSeconds(Calendar startDate, Calendar endDate, String locale) {

    Period period = new Period(startDate.getTimeInMillis(), endDate.getTimeInMillis(),
            PeriodType.standard().withSecondsRemoved().withMillisRemoved());

    String l = locale == null ? Locale.getDefault().toString() : locale;
    return PeriodFormat.wordBased(Locale.forLanguageTag(l.replaceAll("_", "-"))).print(period);
}