public static String compactDecimal(final Number value)
{
    NumberFormat fmt = context.get().getCompactDecimalFormat();
    return fmt.format(value);
} public static DateFormat dateFormatInstance(final String pattern)
{
    return DateFormat.getPatternInstance(pattern, context.get().getLocale());
} public static DecimalFormat decimalFormatInstance(final String pattern)
{
    DecimalFormat decFmt = context.get().getDecimalFormat();
    decFmt.applyPattern(pattern);
    return decFmt;
} public static String duration(final Number value)
{
    // NOTE: does not support any other locale
    return withinLocale(new Callable<String>()
    {
        public String call() throws Exception
        {
            return context.get().getRuleBasedNumberFormat(RuleBasedNumberFormat.DURATION).format(value);
        }
    }, Locale.ENGLISH);
} public static String formatCurrency(final Number value)
{
    DecimalFormat decf = context.get().getCurrencyFormat();
    return stripZeros(decf, decf.format(value));
} public static String formatDate(final Date value)
{
    return formatDate(DateFormat.SHORT, value);
} public static String formatDateTime(final Date value)
{
    return context.get().formatDateTime(value);
} public static String formatDecimal(final Number value)
{
    return context.get().formatDecimal(value);
} public static String formatPercent(final Number value)
{
    return context.get().getPercentFormat().format(value);
} public static String formatPluralCurrency(final Number value)
{
    DecimalFormat decf = context.get().getPluralCurrencyFormat();
    return stripZeros(decf, decf.format(value));
} public static MessageFormat messageFormatInstance(final String pattern)
{
    MessageFormat msg = context.get().getMessageFormat();
    msg.applyPattern(pattern);
    return msg;
} public static String naturalDay(final Date value)
{
    return naturalDay(DateFormat.RELATIVE_SHORT, value);
} public static String naturalTime(final Date duration)
{
    return context.get().getDurationFormat().formatDurationFromNowTo(duration);
} public static String ordinalize(final Number value)
{
    return context.get().getRuleBasedNumberFormat(RuleBasedNumberFormat.ORDINAL).format(value);
} public static Number parseNumber(final String text) throws ParseException
{
    return context.get().getRuleBasedNumberFormat(RuleBasedNumberFormat.SPELLOUT).parse(text);
} public static String pluralize(final Locale locale, final String pattern, final Number value,
        final Object... args)
{
    return withinLocale(new Callable<String>()
    {
        @Override
        public String call() throws Exception
        {
            return pluralize(pattern, value, args);
        }

    }, locale);
} public static String replaceSupplementary(final String value)
{
    return InterpolationHelper.replaceSupplementary(value, new Replacer()
    {
        public String replace(String in)
        {
            return Strings.nullToEmpty(UCharacter.getName(in, ", "));
        }
    });
} public static String smartDateFormat(final Date value, final String skeleton)
{
    return formatDate(value, context.get().getBestPattern(skeleton));
} public static String spellNumber(final Number value)
{
    return context.get().getRuleBasedNumberFormat(RuleBasedNumberFormat.SPELLOUT).format(value);
} public static String transliterate(final String text)
{
    return transliterate(text, "Latin");
} public class MessageFormat extends com.ibm.icu.text.MessageFormat
{

    private static final long serialVersionUID = -5384364921909539710L;

    public MessageFormat(String pattern)
    {

        super(pattern);

    }

    public MessageFormat(String pattern, Locale locale)
    {

        super(pattern, locale);

    }

    public String render(Object... arguments)
    {

        return format(arguments);

    }

    public StringBuffer render(StringBuffer buffer, Object... arguments)
    {

        return format(arguments, buffer, null);

    }

}
import static humanize.ICUHumanize.compactDecimal;
import static humanize.ICUHumanize.dateFormatInstance;
import static humanize.ICUHumanize.decimalFormatInstance;
import static humanize.ICUHumanize.duration;
import static humanize.ICUHumanize.formatCurrency;
import static humanize.ICUHumanize.formatDate;
import static humanize.ICUHumanize.formatDateTime;
import static humanize.ICUHumanize.formatDecimal;
import static humanize.ICUHumanize.formatPercent;
import static humanize.ICUHumanize.formatPluralCurrency;
import static humanize.ICUHumanize.messageFormatInstance;
import static humanize.ICUHumanize.naturalDay;
import static humanize.ICUHumanize.naturalTime;
import static humanize.ICUHumanize.ordinalize;
import static humanize.ICUHumanize.parseNumber;
import static humanize.ICUHumanize.pluralize;
import static humanize.ICUHumanize.replaceSupplementary;
import static humanize.ICUHumanize.smartDateFormat;
import static humanize.ICUHumanize.spellNumber;
import static humanize.ICUHumanize.transliterate;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import humanize.icu.spi.MessageFormat;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.ibm.icu.text.CompactDecimalFormat.CompactStyle;

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void formattersTest()
    {

        for (int i = 0; i < 3; i++)
        {
            assertEquals(decimalFormatInstance("@@##").format(i + 1.14159), String.format("%d.142", (i + 1)));
            assertEquals(decimalFormatInstance("@@##", ES).format(i + 1.14159), String.format("%d,142", (i + 1)));
        }

        int day = rand.nextInt(20) + 1;
        Date date = newTestDate(day, 11, 2015);
        assertEquals(dateFormatInstance("dd/MM/yyyy").format(date), String.format("%02d/%d/%d", day, 12, 2015));
        assertEquals(dateFormatInstance("dd/MM/yyyy", ES).format(date), String.format("%02d/%d/%d", day, 12, 2015));

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void naturalDayTest()
    {

        Calendar cal = Calendar.getInstance();
        assertEquals(naturalDay(cal.getTime()), "today");
        cal.add(Calendar.DATE, 1);
        assertEquals(naturalDay(cal.getTime()), "tomorrow");
        cal.add(Calendar.DAY_OF_MONTH, -2);
        assertEquals(naturalDay(cal.getTime()), "yesterday");
        cal.add(Calendar.DAY_OF_WEEK, -1);
        assertEquals(naturalDay(cal.getTime()), formatDate(cal.getTime()));

        cal.setTime(new Date());
        assertEquals(naturalDay(cal.getTime(), ES), "hoy");
        cal.add(Calendar.DATE, 1);
        assertEquals(naturalDay(cal.getTime(), ES), "mañana");
        cal.add(Calendar.DATE, -2);
        assertEquals(naturalDay(cal.getTime(), ES), "ayer");

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void naturalTimeTest()
    {

        assertTrue(naturalTime(new Date(0), new Date(10)).endsWith(" from now"));

        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 12)), "12 minutes from now");
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 3)), "3 hours from now");
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 24 * 1)), "1 day from now");
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 24 * 3)), "3 days from now");
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 24 * 7 * 3)), "3 weeks from now");
        assertEquals(naturalTime(new Date(0), new Date(2629743830L * 3L)), "2 months from now");
        assertEquals(naturalTime(new Date(0), new Date(2629743830L * 13L * 3L)), "3 years from now");
        assertEquals(naturalTime(new Date(0), new Date(315769289947L * 3L)), "30 years from now");
        assertEquals(naturalTime(new Date(0), new Date(3155792597470L * 3L)), "300 years from now");

        assertEquals(naturalTime(new Date(6000), new Date(0)), "6 seconds ago");
        assertEquals(naturalTime(new Date(1000 * 60 * 12), new Date(0)), "12 minutes ago");
        assertEquals(naturalTime(new Date(1000 * 60 * 60 * 3), new Date(0)), "3 hours ago");
        assertEquals(naturalTime(new Date(1000 * 60 * 60 * 24 * 1), new Date(0)), "1 day ago");
        assertEquals(naturalTime(new Date(1000 * 60 * 60 * 24 * 3), new Date(0)), "3 days ago");
        assertEquals(naturalTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), new Date(0)), "3 weeks ago");
        assertEquals(naturalTime(new Date(2629743830L * 3L), new Date(0)), "2 months ago");
        assertEquals(naturalTime(new Date(2629743830L * 13L * 3L), new Date(0)), "3 years ago");
        assertEquals(naturalTime(new Date(315769289947L * 3L), new Date(0)), "30 years ago");
        assertEquals(naturalTime(new Date(3155792597470L * 3L), new Date(0)), "300 years ago");

        // within locale
        assertTrue(naturalTime(new Date(0), new Date(10), ES).startsWith("dentro de"));
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 3), ES), "dentro de 3 horas");
        assertEquals(naturalTime(new Date(0), new Date(1000 * 60 * 60 * 24 * 1), ES), "dentro de un día");
        assertEquals(naturalTime(new Date(315769289947L * 3L), new Date(0), ES), "hace 30 años");
        assertEquals(naturalTime(new Date(3155792597470L * 3L), new Date(0), ES), "hace 300 años");

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void ordinalizeTest()
    {

        assertEquals(ordinalize(0), "0th");
        assertEquals(ordinalize(1), "1st");
        assertEquals(ordinalize(2), "2nd");
        assertEquals(ordinalize(3), "3rd");
        assertEquals(ordinalize(4), "4th");
        assertEquals(ordinalize(5), "5th");
        assertEquals(ordinalize(33), "33rd");
        assertEquals(ordinalize(11), "11th");
        assertEquals(ordinalize(12), "12th");
        assertEquals(ordinalize(13), "13th");
        assertEquals(ordinalize(10), "10th");
        assertEquals(ordinalize(22), "22nd");
        assertEquals(ordinalize(101), "101st");
        assertEquals(ordinalize(-10), "−10th");
        assertEquals(ordinalize(1.25), "1st");
        assertEquals(ordinalize(new Float(1.33)), "1st");
        assertEquals(ordinalize(new Long(10000000)), "10,000,000th");

        assertEquals(ordinalize(1, ES), "1º");
        assertEquals(ordinalize(20, ES), "20º");

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void parseNumberTest() throws ParseException
    {

        assertEquals(parseNumber("one hundred twenty-three").intValue(), 123);
        assertEquals(parseNumber("doscientos un mil doscientos cincuenta y seis", ES).intValue(), 201256);

    }

    @Test(threadPoolSize = 10, invocationCount = 10)
    public void pluralizeWithFormatInstance()
    {

        int df = rand.nextInt(9);

        MessageFormat f = messageFormatInstance("There {0, plural, one{is one file}other{are {0} files}} on {1}.");