Example usage for org.apache.commons.lang3.time DateUtils getFragmentInHours

List of usage examples for org.apache.commons.lang3.time DateUtils getFragmentInHours

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateUtils getFragmentInHours.

Prototype

public static long getFragmentInHours(final Calendar calendar, final int fragment) 

Source Link

Document

Returns the number of hours within the fragment.

Usage

From source file:de.tor.tribes.types.TimeSpan.java

@Override
public String toString() {
    String result = null;/*from  w  w  w . ja  v  a2  s . c o  m*/

    if (isValidAtSpecificDay()) {
        SimpleDateFormat fDate = new SimpleDateFormat("dd.MM.yy");
        int startHour = (int) DateUtils.getFragmentInHours(new Date(getSpan().getMinimum()), Calendar.DATE);
        int endHour = (int) DateUtils.getFragmentInHours(new Date(getSpan().getMaximum() + 1), Calendar.DATE);

        result = "Am " + fDate.format(getDate()) + ", von " + startHour + " Uhr bis " + endHour + " Uhr";
    } else if (isValidAtEveryDay()) {
        int startHour = (int) (getSpan().getMinimum() / DateUtils.MILLIS_PER_HOUR);
        int endHour = (int) ((getSpan().getMaximum() + 1) / DateUtils.MILLIS_PER_HOUR);

        result = "T\u00E4glich, von " + startHour + " Uhr bis " + endHour + " Uhr";
    } else if (isValidAtExactTime()) {
        SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss 'Uhr'");
        result = "Am " + f.format(getSpan().getMinimum());
    } else if (isValidAtManualRange()) {
        SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy 'um' HH:mm:ss 'Uhr'");
        result = "Von " + f.format(new Date(getSpan().getMinimum())) + " bis "
                + f.format(new Date(getSpan().getMaximum()));
    } else {
        result = "";
    }

    return result;
}