Example usage for org.joda.time Duration isShorterThan

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

Introduction

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

Prototype

public boolean isShorterThan(ReadableDuration duration) 

Source Link

Document

Is the length of this duration shorter than the duration passed in.

Usage

From source file:julian.lylly.model.Prospect.java

public boolean tooLow(Duration timespent) {
    return isOver() && timespent.isShorterThan(min);
}

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

License:Mozilla Public License

static LocalDateTime parseDateTime(String string) {
    if (string == null)
        return null;
    reinitIfNeeded();//ww w.  j  a  v  a 2 s  .com

    string = string.replace("Stand:", "").replace("Import:", "").trim();
    int i = 0;
    for (DateTimeFormatter f : dateTimeFormatters) {
        try {
            LocalDateTime dt = f.parseLocalDateTime(string);
            if (dateTimeFormats[i].contains("yyyy")) {
                return dt;
            } else {
                Duration currentYearDifference = abs(new Duration(DateTime.now(), dt.toDateTime()));
                Duration lastYearDifference = abs(new Duration(DateTime.now(), dt.minusYears(1).toDateTime()));
                Duration nextYearDifference = abs(new Duration(DateTime.now(), dt.plusYears(1).toDateTime()));
                if (lastYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() - 1).parseLocalDateTime(string);
                } else if (nextYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() + 1).parseLocalDateTime(string);
                } else {
                    return dt;
                }
            }
        } catch (IllegalArgumentException e) {
            // Does not match this format, try the next one
        }
        i++;
    }
    // Does not match any known format :(
    return null;
}

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  w ww.  j  a v a 2s  .c  o m
        return duration;
    }
}

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

License:Mozilla Public License

static LocalDate parseDate(String string) {
    if (string == null)
        return null;
    reinitIfNeeded();/*w w w.j a  v  a  2s.  co m*/

    string = string.replace("Stand:", "").replace("Import:", "").replaceAll(", Woche [A-Z]", "").trim();
    int i = 0;
    for (DateTimeFormatter f : dateFormatters) {
        try {
            LocalDate d = f.parseLocalDate(string);
            if (dateFormats[i].contains("yyyy")) {
                return d;
            } else {
                Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime()));
                Duration lastYearDifference = abs(
                        new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime()));
                Duration nextYearDifference = abs(
                        new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime()));
                if (lastYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() - 1).parseLocalDate(string);
                } else if (nextYearDifference.isShorterThan(currentYearDifference)) {
                    return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN)
                            .withDefaultYear(f.getDefaultYear() + 1).parseLocalDate(string);
                } else {
                    return d;
                }
            }
        } catch (IllegalArgumentException e) {
            // Does not match this format, try the next one
        }
        i++;
    }
    // Does not match any known format :(
    return null;
}

From source file:myAgents.AgentGUI.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

    String beginHour = jComboBox1.getSelectedItem().toString();
    if (beginHour.equals(null)) {

        throw new IllegalArgumentException("Evento no enviado");

    }/*from   w w  w  .  j a  v  a  2  s  . c  o m*/
    String endHour = jComboBox2.getSelectedItem().toString();
    if (endHour.equals(null)) {
        throw new IllegalArgumentException("Evento no enviado");
    }

    if (endHour.equals(beginHour)) {
        throw new IllegalArgumentException("Evento no enviado");
    }
    String name = jTextField1.getText();
    if (name.equals(null)) {
        throw new IllegalArgumentException("Evento no enviado");
    }

    String duration = jComboBox3.getSelectedItem().toString();
    if (duration.equals(null)) {
        throw new IllegalArgumentException("Evento no enviado");
    }

    DateTime hourEnd = stringToDateTime(endHour);
    DateTime hourBegin = stringToDateTime(beginHour);
    Duration durationTime = stringToDuration(duration);
    Duration hourDuration = new Duration(hourBegin, hourEnd);

    if (hourEnd.isBefore(hourBegin) || hourBegin.isAfter(hourEnd) || hourDuration.isShorterThan(durationTime)) {
        throw new IllegalArgumentException("Evento no enviado");
    }

    int[] selectedTableIndices = jTable2.getSelectedRows();

    if (selectedTableIndices.length == 0) {
        throw new IllegalArgumentException("Evento no enviado");
    }

    Map<String, Boolean> eventAgents = new HashMap<String, Boolean>();

    for (int i = 0; i < selectedTableIndices.length; i++) {
        //nao esta a ter em conta se os agentaes so mandatorios ou nao... ter em atenao!!
        //if(jTable2.getValueAt(selectedTableIndices[i], 1).equals("true"))
        if (jTable2.getValueAt(selectedTableIndices[i], 0).toString().equals("true"))
            eventAgents.put(jTable2.getValueAt(selectedTableIndices[i], 0).toString(), true);
        else
            eventAgents.put(jTable2.getValueAt(selectedTableIndices[i], 0).toString(), false);

    }

    //alterar
    //Event event =  new Event(hourBegin, hourEnd, hourDuration, eventAgents,name, this.localAgent.getLocalName());
    //this.localAgent.sendMsg(event);

    jDialog1.setVisible(false);

}

From source file:net.schweerelos.timeline.model.Timeline.java

License:Open Source License

public Set<PayloadInterval<T>> getVisibleIntervals(Duration minLength) {
    Set<PayloadInterval<T>> result = new HashSet<PayloadInterval<T>>();
    List<PayloadInterval<T>> intervals = allIntervals.getIntervals();
    for (PayloadInterval<T> interval : intervals) {
        DateTime intervalStart = interval.getStart();
        DateTime intervalEnd = interval.getEnd();

        // if interval is completely outside of time shown in timeline
        // -> skip this interval
        if (intervalEnd.isBefore(start) || intervalStart.isAfter(end)) {
            continue;
        }/*from   w w  w .  j a v a 2  s.  c om*/

        // if interval is too short
        // -> skip this interval
        Duration length = interval.toInterval().toDuration();
        if (length.isShorterThan(minLength)) {
            continue;
        }

        if (isWithinRange(intervalStart)) {
            if (isWithinRange(intervalEnd)) {
                // interval is completely inside time shown in timeline
                result.add(interval);
            } else {
                // interval starts during timeline but ends later
                result.add(interval);
            }
        } else if (isWithinRange(intervalEnd)) {
            // interval starts before timeline but ends within
            result.add(interval);
        } else {
            // interval start before timeline and ends later
            result.add(interval);
        }
    }
    return result;
}

From source file:org.agatom.springatom.web.validator.AppointmentValidator.java

License:Open Source License

private void validateDates(final NAppointment appointment, final ValidationContext context) {
    final MessageContext messageContext = context.getMessageContext();
    final MessageBuilder messageBuilder = new MessageBuilder();

    final DateTime begin = appointment.getBegin();
    final DateTime end = appointment.getEnd();

    final int beginHourOfDay = begin.getHourOfDay();
    final int endHourOfDay = end.getHourOfDay();
    if (beginHourOfDay < this.minTime) {
        messageContext.addMessage(messageBuilder.source("begin").error()
                .defaultText(String.format("Begin hour must not be lower than %d", this.minTime)).build());
    }//from ww w  .  j  av a  2 s  .  c o m
    if (endHourOfDay > this.maxTime) {
        messageContext.addMessage(messageBuilder.source("end").error()
                .defaultText(String.format("End hour must not be higher than %d", this.maxTime)).build());
    }
    if (begin.isAfter(end)) {
        messageContext.addMessage(
                messageBuilder.source("begin").error().defaultText("Begin must be before End").build());
    } else {
        final Duration duration = new Duration(end.minus(begin.getMillis()).getMillis());
        if (duration.isShorterThan(new Duration(this.minDiffBetweenDates))) {
            messageContext
                    .addMessage(
                            messageBuilder.source("interval").warning()
                                    .defaultText(String.format("Time of appointment is shorter than %d minutes",
                                            TimeUnit.MILLISECONDS.toMinutes(this.minDiffBetweenDates)))
                                    .build());
        } else if (duration.isLongerThan(new Duration(this.maxDiffBetweenDates))) {
            messageContext.addMessage(messageBuilder.source("interval").warning()
                    .defaultText(String.format("Time of appointment is longer than %d days",
                            TimeUnit.MILLISECONDS.toDays(this.maxDiffBetweenDates)))
                    .build());
        }
    }
}

From source file:org.apache.beam.runners.dataflow.DataflowPipelineJob.java

License:Apache License

private static BackOff getMessagesBackoff(Duration duration) {
    FluentBackoff factory = MESSAGES_BACKOFF_FACTORY;

    if (!duration.isShorterThan(Duration.ZERO)) {
        factory = factory.withMaxCumulativeBackoff(duration);
    }/*from   w  ww . j av a2  s .  co m*/

    return BackOffAdapter.toGcpBackOff(factory.backoff());
}

From source file:org.smartdeveloperhub.harvesters.it.testing.generator.ProjectActivityGenerator.java

License:Apache License

private Duration estimateEffort(final LocalDateTime start, final LocalDateTime dueTo) {
    final Days daysBetween = Days.daysBetween(start, dueTo);
    int workingDays = 0;
    for (int i = 0; i < daysBetween.getDays(); i++) {
        if (Utils.isWorkingDay(start.toLocalDate().plusDays(i))) {
            workingDays++;//ww w.  ja v a  2  s . c  o m
        }
    }
    final int maxMinutes = workingDays * this.workDay.effortPerDay();
    final double ratio = (100 + this.random.nextInt(900)) / 1000d;
    Duration result = Duration.standardMinutes(
            33 * maxMinutes / 100 + DoubleMath.roundToInt(67 * maxMinutes / 100 * ratio, RoundingMode.CEILING));
    if (result.isShorterThan(MINIMUM_EFFORT)) {
        result = MINIMUM_EFFORT;
    }
    return result;
}

From source file:org.sonar.server.issue.index.IssueIndex.java

License:Open Source License

private AggregationBuilder getCreatedAtFacet(IssueQuery query, Map<String, FilterBuilder> filters,
        QueryBuilder esQuery) {//  w  w w .ja  v a2s  .  co m
    long now = system.now();

    String timeZoneString = system.getDefaultTimeZone().getID();

    DateHistogram.Interval bucketSize = DateHistogram.Interval.YEAR;
    Date createdAfter = query.createdAfter();
    long startTime = createdAfter == null ? getMinCreatedAt(filters, esQuery) : createdAfter.getTime();
    Date createdBefore = query.createdBefore();
    long endTime = createdBefore == null ? now : createdBefore.getTime();

    Duration timeSpan = new Duration(startTime, endTime);

    if (timeSpan.isShorterThan(TWENTY_DAYS)) {
        bucketSize = DateHistogram.Interval.DAY;
    } else if (timeSpan.isShorterThan(TWENTY_WEEKS)) {
        bucketSize = DateHistogram.Interval.WEEK;
    } else if (timeSpan.isShorterThan(TWENTY_MONTHS)) {
        bucketSize = DateHistogram.Interval.MONTH;
    }

    AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(CREATED_AT)
            .field(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT).interval(bucketSize).minDocCount(0L)
            .format(DateUtils.DATETIME_FORMAT).timeZone(timeZoneString).postZone(timeZoneString)
            .extendedBounds(startTime, endTime);
    dateHistogram = addEffortAggregationIfNeeded(query, dateHistogram);
    return dateHistogram;
}