class TimeSpanFormatter {

    public static String toSmartString(TimeSpan timeSpan)
    {
        String displayString;
        if (timeSpan.isTimeless() || timeSpan.isZero() || timeSpan.isInstantaneous())
        {
            displayString = toDisplayString(timeSpan);
        }
        else
        {
            Calendar startCal = Calendar.getInstance();
            startCal.setTimeInMillis(timeSpan.getStart());

            Calendar endCal = Calendar.getInstance();
            endCal.setTimeInMillis(timeSpan.getEnd());

            if (CalendarUtilities.isClearedFrom(startCal, CalendarUtilities.DAY_INDEX)
                    && CalendarUtilities.isClearedFrom(endCal, CalendarUtilities.DAY_INDEX))
            {
                if (timeSpan.getDuration().equals(Months.ONE))
                {
                    displayString = formatStart(timeSpan, MONTH_FORMAT);
                }
                else
                {
                    displayString = buildString(minusEnd(timeSpan, Months.ONE), MONTH_FORMAT, " - ", new StringBuilder(19))
                            .toString();
                }
            }
            else if (CalendarUtilities.isClearedFrom(startCal, CalendarUtilities.HOUR_INDEX)
                    && CalendarUtilities.isClearedFrom(endCal, CalendarUtilities.HOUR_INDEX))
            {
                if (timeSpan.getDuration().equals(Days.ONE))
                {
                    displayString = formatStart(timeSpan, DATE_FORMAT);
                }
                else
                {
                    displayString = buildString(minusEnd(timeSpan, Days.ONE), DATE_FORMAT, " - ", new StringBuilder(23))
                            .toString();
                }
            }
            else
            {
                displayString = toDisplayString(timeSpan);
            }
        }
        return displayString;
    }

    private  TimeSpanFormatter();

}