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(Object duration) 

Source Link

Document

Creates a duration from the specified object using the org.joda.time.convert.ConverterManager ConverterManager .

Usage

From source file:kr.debop4j.timeperiod.TimeBlock.java

License:Apache License

@Override
public ITimeBlock getPreviousBlock(Duration offset) {
    Duration endOffset = (offset.compareTo(ZERO) > 0) ? new Duration(-offset.getMillis()) : offset;
    return new TimeBlock(getDuration(), getStart().plus(endOffset), readonly);
}

From source file:kr.debop4j.timeperiod.TimeBlock.java

License:Apache License

@Override
public ITimeBlock getNextBlock(Duration offset) {
    Duration startOffset = (offset.compareTo(ZERO) > 0) ? offset : new Duration(-offset.getMillis());
    return new TimeBlock(getEnd().plus(startOffset), getDuration(), readonly);
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/** ???  ? . */
public static Duration getTime(DateTime moment) {
    return new Duration(moment.getMillisOfDay());
}

From source file:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Adjust period./*from  ww  w  .  j  a v  a  2s  .com*/
 *
 * @param start    the start
 * @param duration the duration
 * @return the pair
 */
public static Pair<DateTime, Duration> adjustPeriod(DateTime start, Duration duration) {
    shouldNotBeNull(start, "start");
    shouldNotBeNull(duration, "duration");
    return (duration.getMillis() < 0) ? Pair.create(start.plus(duration), new Duration(-duration.getMillis()))
            : Pair.create(start, duration);
}

From source file:me.vertretungsplan.parser.ParserUtils.java

License:Mozilla Public License

private static Duration abs(Duration duration) {
    Duration nothing = new Duration(0);
    if (duration.isShorterThan(nothing)) {
        return duration.negated();
    } else {/*from www.  j  av  a2  s  .  com*/
        return duration;
    }
}

From source file:module.workflow.domain.FileUploadLog.java

License:Open Source License

/**
 * /*from  www . j a  v a  2 s .  c  om*/
 * @return true if FileUploadLog has a date 1min within processFile's
 *         creation date, and the names and other details match
 */
private static boolean matches(FileUploadLog fileUploadLog, ProcessFile processFile) {
    DateTime creationDate = processFile.getCreationDate();
    if (creationDate == null) {
        throw new IllegalArgumentException("File: " + processFile.getExternalId() + " of class: "
                + processFile.getClass().getSimpleName() + " has no creation date");
    }

    DateTime whenOperationWasRan = fileUploadLog.getWhenOperationWasRan();

    Interval interval = null;
    if (creationDate.isBefore(whenOperationWasRan)) {
        interval = new Interval(creationDate, whenOperationWasRan);
    } else {

        interval = new Interval(whenOperationWasRan, creationDate);
    }
    if (interval.toDuration().isLongerThan(new Duration(60000))) {
        return false;
    }
    Strings descriptionArguments = fileUploadLog.getDescriptionArguments();
    if (!descriptionArguments.hasStringIgnoreCase(processFile.getFilename())) {
        return false;
    }
    if (!descriptionArguments.hasStringIgnoreCase(processFile.getDisplayName())) {
        return false;
    }

    return true;

}

From source file:name.gano.astro.time.Time.java

License:Open Source License

public static GregorianCalendar convertJD2Calendar(double jd) {
    return MJD_EPOCH.plus(new Duration((long) (mjdOfJd(jd) * 24 * 60 * 60000)))
            .toDateTime(DateTimeZone.forTimeZone(tz)).toGregorianCalendar();
}

From source file:net.sf.jacclog.service.importer.commands.internal.ImportStatsShellCommand.java

License:Apache License

private void renderEntries(final LogFileImporterStatistic statistic) {
    if (statistic.getEntries() != null && !statistic.getEntries().isEmpty()) {
        final int size = (statistic.getEntries().get(0).getFile() != null)
                ? statistic.getEntries().get(0).getFile().getFile().getPath().length() + 8
                : 32;/*from  w w  w  .  ja  va  2 s  .  co m*/
        final String format = "%-" + size + "s%10s%18s";
        final StringBuilder builder = new StringBuilder();
        builder.append('\n');
        final Formatter formatter = new Formatter(builder);
        formatter.format(format, "Path", "Count", "Elapsed time");
        builder.append('\n');

        String path;
        Period p;
        int totalCount = 0;
        Duration totalElapsedTime = new Duration(0);
        for (final Entry entry : statistic.getEntries()) {
            path = entry.getFile().getFile().getPath();
            p = entry.getElapsedTime();
            totalElapsedTime = totalElapsedTime.plus(p.toStandardDuration());
            totalCount += entry.getCount();
            formatter.format(format, path, entry.getCount(), p.toString(FORMATTER));
            builder.append('\n');
        }

        builder.append('\n');
        builder.append("Total imported entries: " + totalCount);
        builder.append('\n');
        builder.append("Total processing time: " + totalElapsedTime.toPeriod().toString(FORMATTER));
        builder.append('\n');

        System.out.println(builder);
    } else {
        System.out.println("No files have been recently imported.");
    }
}

From source file:net.sf.janos.util.TimeUtilities.java

License:Apache License

/**
 * Converts the given java date to an ISO8601 duration.
 * @param duration//  ww w  .java 2  s. c o  m
 * @return
 */
public static String convertLongToISO8601Duration(long duration) {
    return new Duration(duration).toString();
}

From source file:net.sf.janos.util.TimeUtilities.java

License:Apache License

/**
 * Parses the given ISO8601 Duration formatted string to a java date.
 * @param duration/*  ww  w. j  ava 2 s  .c o  m*/
 * @return
 * @throws IllegalArgumentException if duration is not of ISO8601 duration format.
 */
public static long convertISO8601DurationToLong(String duration) {
    return new Duration(duration).getMillis();
}