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

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

Introduction

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

Prototype

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

Source Link

Document

Returns the number of milliseconds within the fragment.

Usage

From source file:com.stratelia.webactiv.util.DateUtil.java

public static String getOutputDateAndHour(Date date, String language) {
    if (isNotDefined(date)) {
        return "";
    }//from  ww w.  ja v a 2 s  .c om
    if (DateUtils.getFragmentInMilliseconds(date, Calendar.DAY_OF_MONTH) == 0L) {
        // this case is useful on data recovery
        // avoiding to display an useless information about hour (00:00) when given date have an hour
        // like 0:00:00.000
        return getOutputDate(date, language);
    }
    FastDateFormat formatter = FastDateFormat
            .getInstance(getMultilangProperties(language).getString("dateOutputFormat") + " "
                    + getMultilangProperties(language).getString("hourOutputFormat"));
    return formatter.format(date);
}

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

public boolean intersects(TimeSpan pSpan) {
    if (!this.getDirection().equals(pSpan.getDirection())) {
        //different directions
        return false;
    }/* www .j  a  v  a 2s .  com*/

    //one of the spans uses manual Time (new intersect)
    Range<Long> thisSpan = this.getSpan();
    Range<Long> theOtherSpan = pSpan.getSpan();

    if (this.isValidAtEveryDay() || pSpan.isValidAtEveryDay()) {
        if (this.isValidAtSpecificDay() || pSpan.isValidAtSpecificDay()) {
            //remove day Information
            Long thisStart = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMinimum()),
                    Calendar.DATE);
            Long thisEnd = DateUtils.getFragmentInMilliseconds(new Date(thisSpan.getMaximum()), Calendar.DATE);
            thisSpan = Range.between(thisStart, thisEnd);

            Long otherStart = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMinimum()),
                    Calendar.DATE);
            Long otherEnd = DateUtils.getFragmentInMilliseconds(new Date(theOtherSpan.getMaximum()),
                    Calendar.DATE);

            theOtherSpan = Range.between(otherStart, otherEnd);

            return thisSpan.isOverlappedBy(theOtherSpan);
        } else if (this.isValidAtEveryDay() && pSpan.isValidAtEveryDay()) {
            //both valid at every Day - just compare spans
            return thisSpan.isOverlappedBy(theOtherSpan);
        } else {
            //one span is for everyDay the other is over multiple Days
            //manual intersect
            Range<Long> always;
            Range<Long> manual;
            if (this.isValidAtEveryDay()) {
                always = thisSpan;
                manual = theOtherSpan;
            } else {
                always = theOtherSpan;
                manual = thisSpan;
            }

            long manualDate = DateUtils.truncate(new Date(manual.getMinimum()), Calendar.DATE).getTime();
            long manualStart = manual.getMinimum() - manualDate;
            long manualEnd = manual.getMaximum() - manualDate;

            if (manualEnd - manualStart > DateUtils.MILLIS_PER_DAY) {
                //must intersect somehow because span is longer than 1 Day
                return true;
            }
            //direct intersection
            manual = Range.between(manualStart, manualEnd);
            if (always.isOverlappedBy(manual))
                return true;

            //should not be possible, because it should be handeld by isValidAtSpecificDay
            if (manualEnd <= DateUtils.MILLIS_PER_DAY)
                return false;

            //maybe intersection at next day
            manual = Range.between(new Long(0), manualEnd - DateUtils.MILLIS_PER_DAY);
            return always.isOverlappedBy(manual);
        }
    }

    return thisSpan.isOverlappedBy(theOtherSpan);
}

From source file:de.tor.tribes.ui.windows.ClockFrame.java

@Override
public void run() {
    while (true) {
        long currentTime = System.currentTimeMillis();
        mParent.updateTime(FORMAT.format(new Date(currentTime)),
                (int) DateUtils.getFragmentInMilliseconds(new Date(), Calendar.SECOND));
        if (mParent.isVisible()) {
            mParent.repaint();// ww w  . j  av  a2s  .  c o m
        } else {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
        }

        try {
            Thread.sleep(50);
        } catch (InterruptedException ignored) {
        }
    }
}

From source file:org.silverpeas.core.util.DateUtil.java

public static String getOutputDateAndHour(Date date, String language) {
    if (isNotDefined(date)) {
        return "";
    }/*from w w w . ja v a  2 s  .co  m*/
    if (DateUtils.getFragmentInMilliseconds(date, Calendar.DAY_OF_MONTH) == 0L) {
        // this case is useful on data recovery
        // avoiding to display an useless information about hour (00:00) when given date have an hour
        // like 0:00:00.000
        return getOutputDate(date, language);
    }
    FastDateFormat formatter = FastDateFormat
            .getInstance(getLocalizedProperties(language).getString("dateOutputFormat") + " "
                    + getLocalizedProperties(language).getString(HOUR_OUTPUT_FORMAT));
    return formatter.format(date);
}