Example usage for org.joda.time Duration Duration

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

Introduction

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

Prototype

public Duration(ReadableInstant start, ReadableInstant end) 

Source Link

Document

Creates a duration from the given interval endpoints.

Usage

From source file:au.com.scds.chats.dom.attendance.Attend.java

License:Apache License

@Property(editing = Editing.DISABLED)
@NotPersistent//from  w ww.j a v  a2  s  .c om
public String getAttendanceInterval() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Duration duration = new Duration(getStartDateTime(), getEndDateTime());
        return String.format("%02d:%02d", duration.getStandardHours(),
                duration.getStandardMinutes() - duration.getStandardHours() * 60);
    } else
        return null;
}

From source file:au.com.scds.chats.dom.attendance.Attend.java

License:Apache License

@Programmatic
public Long getAttendanceIntervalInMinutes() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Duration duration = new Duration(getStartDateTime(), getEndDateTime());
        return duration.getStandardMinutes();
    } else//from   www .  ja  v  a  2s  .  com
        return null;
}

From source file:au.com.scds.chats.dom.call.Call.java

License:Apache License

@Property(editing = Editing.DISABLED, notPersisted = true)
@PropertyLayout(named = "Call Length", describedAs = "The interval that the participant attended the activity (hours:minutes)")
@MemberOrder(sequence = "6")
@NotPersistent//from   w  w  w  .ja  va  2 s  .  c om
public String getCallLength() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Duration duration = new Duration(getStartDateTime(), getEndDateTime());
        return String.format("%01d:%02d", duration.getStandardHours(),
                duration.getStandardMinutes() - duration.getStandardHours() * 60);
    } else
        return null;
}

From source file:au.com.scds.chats.dom.call.Call.java

License:Apache License

public String validateUpdateTimes(DateTime start, DateTime end) {
    if (start.isAfter(end)) {
        return "End Time is before Start Time";
    }// w w w . j ava2 s  . c  o m
    Duration duration = new Duration(getStartDateTime(), getEndDateTime());
    if (duration.getStandardDays() > 0) {
        return "End Time is not on the same date as Start Time";
    }
    return null;
}

From source file:au.com.scds.chats.dom.call.Call.java

License:Apache License

@Programmatic
public Long getCallIntervalInMinutes() {
    if (getStartDateTime() != null && getEndDateTime() != null) {
        Duration duration = new Duration(getStartDateTime(), getEndDateTime());
        return duration.getStandardMinutes();
    } else/*from   www .  jav a2 s .  com*/
        return null;
}

From source file:au.id.hazelwood.xmltvguidebuilder.postprocessor.ListingVerifier.java

License:Apache License

public void verifyListing(ChannelListings listings, DateTime from, DateTime to, DateTime subsetTo) {
    Duration listingDurationTotal = new Interval(from, to).toDuration();
    Duration listingDurationSubset = new Interval(from, subsetTo).toDuration();
    LOGGER.info(repeat("-", 100));
    for (ChannelDetail channelDetail : listings.getChannels()) {
        Duration missingDurationTotal = Duration.ZERO;
        Duration missingDurationSubset = Duration.ZERO;
        StringBuilder allMissingIntervalDetails = new StringBuilder();
        for (Interval missing : findMissingIntervals(listings, from, to, channelDetail.getId())) {
            missingDurationTotal = missingDurationTotal.plus(missing.toDuration());
            if (missing.getStart().isBefore(subsetTo)) {
                if (missing.getEnd().isBefore(subsetTo)) {
                    missingDurationSubset = missingDurationSubset.plus(missing.toDuration());
                } else {
                    missingDurationSubset = missingDurationSubset
                            .plus(new Duration(missing.getStart(), subsetTo));
                }/*from ww w  .  ja va  2s.  com*/
            }
            allMissingIntervalDetails.append(allMissingIntervalDetails.length() == 0 ? "missing " : ", ");
            allMissingIntervalDetails.append(
                    format("{0}-{1}", toISODateTime(missing.getStart()), toISODateTime(missing.getEnd())));
        }
        Duration availableDurationTotal = listingDurationTotal.minus(missingDurationTotal);
        Duration availableDurationSubset = listingDurationSubset.minus(missingDurationSubset);
        Integer availablePercentageTotal = getPercentage(availableDurationTotal, listingDurationTotal);
        Integer availablePercentageSubset = getPercentage(availableDurationSubset, listingDurationSubset);
        LOGGER.info("{} {} [{}|{}] {}", rightPad(channelDetail.getId() + " - " + channelDetail.getName(), 42),
                formatDurationDHM(availableDurationTotal.getMillis()),
                leftPad(availablePercentageSubset + "%", 4), leftPad(availablePercentageTotal + "%", 4),
                allMissingIntervalDetails.toString());
    }
    LOGGER.info(repeat("-", 100));
}

From source file:azkaban.app.ScheduledJob.java

License:Apache License

public Duration getExecutionDuration() {
    if (_started == null || _ended == null)
        throw new IllegalStateException("Job has not completed yet.");
    return new Duration(_started, _ended);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private ScheduledFuture<?> schedule(final ScheduledJob schedJob, boolean saveResults) {
    // fail fast if there is a problem with this job
    _jobManager.validateJob(schedJob.getId());

    Duration wait = new Duration(new DateTime(), schedJob.getScheduledExecution());
    if (wait.getMillis() < -1000) {
        logger.warn("Job " + schedJob.getId() + " is scheduled for "
                + DateTimeFormat.shortDateTime().print(schedJob.getScheduledExecution()) + " which is "
                + (PeriodFormat.getDefault().print(wait.toPeriod()))
                + " in the past, adjusting scheduled date to now.");
        wait = new Duration(0);
    }//from   w  w  w.j a v a2 s  .co m

    // mark the job as scheduled
    _scheduled.put(schedJob.getId(), schedJob);

    if (saveResults) {
        try {
            saveSchedule();
        } catch (IOException e) {
            throw new RuntimeException("Error saving schedule after scheduling job " + schedJob.getId());
        }
    }

    ScheduledRunnable runnable = new ScheduledRunnable(schedJob);
    schedJob.setScheduledRunnable(runnable);
    return _executor.schedule(runnable, wait.getMillis(), TimeUnit.MILLISECONDS);
}

From source file:azkaban.common.web.GuiUtils.java

License:Apache License

public Duration duration(DateTime a, DateTime b) {
    return new Duration(a, b);
}

From source file:azkaban.jobs.JobExecution.java

License:Apache License

public Duration getExecutionDuration() {
    if (startTime == null || endTime == null)
        throw new IllegalStateException("Job has not completed yet.");
    return new Duration(startTime, endTime);
}