Example usage for org.joda.time DateTime minus

List of usage examples for org.joda.time DateTime minus

Introduction

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

Prototype

public DateTime minus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period taken away.

Usage

From source file:net.sourceforge.fenixedu.domain.accounting.postingRules.AdministrativeOfficeFeePR.java

License:Open Source License

public AdministrativeOfficeFeePR edit(DateTime startDate, Money fixedAmount, Money penaltyAmount,
        YearMonthDay whenToApplyFixedAmountPenalty) {

    if (!startDate.isAfter(getStartDate())) {
        throw new DomainException(
                "error.AdministrativeOfficeFeePR.startDate.is.before.then.start.date.of.previous.posting.rule");
    }//from  ww  w  .ja v a  2 s.  c o  m

    deactivate(startDate);

    return new AdministrativeOfficeFeePR(startDate.minus(1000), null, getServiceAgreementTemplate(),
            fixedAmount, penaltyAmount, whenToApplyFixedAmountPenalty);
}

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  a v a 2 s  .  co 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.abdera2.common.date.DateTimes.java

License:Apache License

public static Range<DateTime> atOrBetween(Duration duration, DateTime high) {
    return atOrBetween(high.minus(duration), high);
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static Range<DateTime> atBetweenOrBefore(Duration duration, DateTime high) {
    return atBetweenOrBefore(high.minus(duration), high);
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static Range<DateTime> between(Duration duration, DateTime high) {
    return between(high.minus(duration), high);
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static Range<DateTime> afterBetweenOrAt(Duration duration, DateTime high) {
    return afterBetweenOrAt(high.minus(duration), high);
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static Range<DateTime> exactlyBefore(DateTime date, Duration duration) {
    return exactly(date.minus(duration));
}

From source file:org.apache.abdera2.common.date.DateTimes.java

License:Apache License

public static Selector<DateTime> selectorForAtOrBetween(Duration duration, DateTime high) {
    return selectorForRange(atOrBetween(high.minus(duration), high));
}

From source file:org.apache.beam.sdk.extensions.sql.impl.interpreter.operator.date.BeamSqlDatetimeMinusIntervalExpression.java

License:Apache License

@Override
public BeamSqlPrimitive evaluate(Row row, BoundedWindow window, BeamSqlExpressionEnvironment env) {
    DateTime date = new DateTime(opValueEvaluated(0, row, window, env));
    Period period = intervalToPeriod(op(1).evaluate(row, window, env));

    return BeamSqlPrimitive.of(outputType, date.minus(period));
}

From source file:org.apache.druid.query.TimewarpOperator.java

License:Apache License

public QueryRunner<T> postProcess(final QueryRunner<T> baseRunner, final long now) {
    return new QueryRunner<T>() {
        @Override// ww  w  . j av  a  2 s  .  c o  m
        public Sequence<T> run(final QueryPlus<T> queryPlus, final ResponseContext responseContext) {
            final DateTimeZone tz = queryPlus.getQuery().getTimezone();
            final long offset = computeOffset(now, tz);

            final Interval interval = queryPlus.getQuery().getIntervals().get(0);
            final Interval modifiedInterval = new Interval(
                    Math.min(interval.getStartMillis() + offset, now + offset),
                    Math.min(interval.getEndMillis() + offset, now + offset), interval.getChronology());
            return Sequences.map(baseRunner.run(
                    queryPlus.withQuerySegmentSpec(
                            new MultipleIntervalSegmentSpec(Collections.singletonList(modifiedInterval))),
                    responseContext), new Function<T, T>() {
                        @Override
                        public T apply(T input) {
                            if (input instanceof Result) {
                                Result res = (Result) input;
                                Object value = res.getValue();
                                if (value instanceof TimeBoundaryResultValue) {
                                    TimeBoundaryResultValue boundary = (TimeBoundaryResultValue) value;

                                    DateTime minTime;
                                    try {
                                        minTime = boundary.getMinTime();
                                    } catch (IllegalArgumentException e) {
                                        minTime = null;
                                    }

                                    final DateTime maxTime = boundary.getMaxTime();

                                    return (T) ((TimeBoundaryQuery) queryPlus.getQuery()).buildResult(
                                            DateTimes.utc(
                                                    Math.min(res.getTimestamp().getMillis() - offset, now)),
                                            minTime != null ? minTime.minus(offset) : null,
                                            maxTime != null
                                                    ? DateTimes.utc(Math.min(maxTime.getMillis() - offset, now))
                                                    : null)
                                            .iterator().next();
                                }
                                return (T) new Result(res.getTimestamp().minus(offset), value);
                            } else if (input instanceof MapBasedRow) {
                                MapBasedRow row = (MapBasedRow) input;
                                return (T) new MapBasedRow(row.getTimestamp().minus(offset), row.getEvent());
                            }

                            // default to noop for unknown result types
                            return input;
                        }
                    });
        }
    };
}