Example usage for org.joda.time Interval Interval

List of usage examples for org.joda.time Interval Interval

Introduction

In this page you can find the example usage for org.joda.time Interval Interval.

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:com.axelor.apps.crm.service.EventReminderService.java

License:Open Source License

public Duration computeDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) {

    return new Interval(startDateTime.toDateTime(), endDateTime.toDateTime()).toDuration();

}

From source file:com.axelor.apps.organisation.service.LeaveRequestService.java

License:Open Source License

public Duration computeDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) {

    return new Interval(startDateTime.toDateTime(), endDateTime.toDateTime()).toDuration();
}

From source file:com.axelor.apps.tool.date.DurationTool.java

License:Open Source License

public static Duration computeDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) {

    return new Interval(startDateTime.toDateTime(), endDateTime.toDateTime()).toDuration();
}

From source file:com.baulsupp.kolja.ansi.reports.basic.ActiveRequests.java

License:Open Source License

private Interval calculateInterval(RequestLine line) {
    if (from == null || to == null) {
        return null;
    }/*from  w  w  w.jav  a 2 s.  c o  m*/

    DateTime t = (DateTime) line.getValue(LogConstants.DATE);

    return new Interval(from.toDateTime(t), to.toDateTime(t));
}

From source file:com.baulsupp.kolja.log.viewer.request.StandardRequestIndex.java

License:Open Source License

@Override
protected void updateLine(Line line, RequestLine requestLine, IntList values) {
    requestLine.addLine(line);// w ww .  j a  v  a 2 s  .co m

    updateMatchers(line, requestLine);

    String message = (String) line.getValue(messageField);

    if (message != null) {
        boolean complete = requestLine.isComplete();

        if (message.contains(beginPattern)) {
            requestLine.setStartFound(true);

            if (dateField != null) {
                DateTime d = (DateTime) line.getValue(dateField);
                requestLine.setValue(dateField, d);
            }
        }

        if (message.contains(endPattern)) {
            requestLine.setEndFound(true);

            requestLine.setOffset(line.getOffset());

            DateTime d = (DateTime) line.getValue(dateField);
            requestLine.setValue(dateField + "-end", d);

            if (offsetIsEnd) {
                requests.put(line.getIntOffset(), requestLine);
                if (values != null) {
                    values.add(line.getIntOffset());
                }
            }
        }

        if (!complete && requestLine.isComplete()) {
            DateTime start = (DateTime) requestLine.getValue(dateField);
            DateTime end = (DateTime) requestLine.getValue(dateField + "-end");

            if (start != null && end != null) {
                Interval interval = new Interval(start, end);
                requestLine.setValue(LogConstants.INTERVAL, interval);
            }

            requestLine.setValue(messageField, statusFormatter.format(requestLine));
        }
    }
}

From source file:com.chessix.vas.actors.JournalActor.java

License:Apache License

/**
 * Update the time delay between creation of the message and processing it.
 *///from  w w w. j a  va 2  s . c  o  m
private void updateTimeDelay(final Date timestamp) {
    final Duration d = new Interval(new DateTime(timestamp), DateTime.now()).toDuration();
    if ((delay == null) || (d.compareTo(delay) > 0)) {
        delay = d;
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *///from w  ww  . j  a va  2 s .c  o  m
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    Timestamp startTimestamp = null;
    Timestamp endTimestamp = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startTimestamp = (Timestamp) inputValues[1];
        // long startMilliseconds = startTimestamp.getTime() +
        // (startTimestamp.getNanos() / 1000000);
        long startMilliseconds = startTimestamp.getTime()
                + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);
        startCal = Calendar.getInstance();
        startCal.setTimeInMillis(startMilliseconds);

        endTimestamp = (Timestamp) inputValues[2];
        // long endMilliseconds = endTimestamp.getTime() +
        // (endTimestamp.getNanos() / 1000000);
        long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);

        endCal = Calendar.getInstance();
        endCal.setTimeInMillis(endMilliseconds);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY),
                startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND),
                startCal.get(Calendar.MILLISECOND));
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY),
                endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND));

        Interval interval = new Interval(startDateTime, endDateTime);

        if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) {
            Seconds seconds = Seconds.secondsIn(interval);
            dateLength = seconds.getSeconds();
        } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) {
            Minutes minutes = Minutes.minutesIn(interval);
            dateLength = minutes.getMinutes();
        } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) {
            Hours hours = Hours.hoursIn(interval);
            dateLength = hours.getHours();
        } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) {
            Days days = Days.daysIn(interval);
            dateLength = days.getDays();
        } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) {
            Weeks weeks = Weeks.weeksIn(interval);
            dateLength = weeks.getWeeks();
        } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) {
            Months months = Months.monthsIn(interval);
            dateLength = months.getMonths();
        } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) {
            Years years = Years.yearsIn(interval);
            dateLength = years.getYears();
        } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) {
            dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis
        } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000L // micros
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000
        } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000000L // nanos
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos
        } else {
            throw new IllegalArgumentException(datePart);
        }

        result = new Long(dateLength);

    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.citruspay.JDateUtil.java

License:Open Source License

public static Interval getISTPreviousDay() {
    DateTimeZone ISTTimeZone = DateTimeZone.forID(Asia_Kolkata);
    DateTime dateTime = new DateTime(ISTTimeZone);
    DateTime from = JDateUtil.startOfDay(dateTime.minusDays(1));
    DateTime to = JDateUtil.startOfDay(dateTime);
    return new Interval(from, to);
}

From source file:com.cronutils.model.time.ExecutionTime.java

License:Apache License

/**
 * Provide nearest time for next execution.
 * @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
 * @return jodatime Duration instance, never null. Time to next execution.
 *//*  w ww.  java  2  s .com*/
public Duration timeToNextExecution(DateTime date) {
    return new Interval(date, nextExecution(date)).toDuration();
}

From source file:com.cronutils.model.time.ExecutionTime.java

License:Apache License

/**
 * Provide nearest time from last execution.
 * @param date - jodatime DateTime instance. If null, a NullPointerException will be raised.
 * @return jodatime Duration instance, never null. Time from last execution.
 *//*from w w  w. j  a v a  2s.c o  m*/
public Duration timeFromLastExecution(DateTime date) {
    return new Interval(lastExecution(date), date).toDuration();
}