Example usage for org.joda.time DateTime plus

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

Introduction

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

Prototype

public DateTime plus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period added.

Usage

From source file:com.metamx.common.Granularity.java

License:Apache License

public final DateTime increment(DateTime time) {
    return time.plus(getUnits(1));
}

From source file:com.metamx.common.Granularity.java

License:Apache License

public final DateTime increment(DateTime time, int count) {
    return time.plus(getUnits(count));
}

From source file:com.nesscomputing.cache.guava.GuavaCacheAdapter.java

License:Apache License

private DateTime getExpiry() {
    if (expiry == null) {
        return DateTime.now().plusYears(10);
    }/*from w  w w  . j  av a2 s .c o  m*/

    DateTime result = DateTime.now().plus(expiry);

    if (expiryJitter != null) {
        result = result.plus((long) (expiryJitter.getMillis() * (Math.random() * 2.0 - 1.0)));
    }

    return result;
}

From source file:com.nesscomputing.cache.PrefixedCache.java

License:Apache License

private DateTime getExpiry() {
    if (expiration == null) {
        return DateTime.now().plusYears(10);
    }//from w  w  w.  jav a  2s  .c  o  m

    DateTime result = DateTime.now().plus(expiration);

    // 0..1 -> 0..jitter*2 - jitter -> -jitter .. +jitter
    return result.plus((long) (random.nextFloat() * 2.0 * jitter) - jitter);
}

From source file:com.ning.billing.osgi.bundles.analytics.dao.model.BusinessSubscription.java

License:Apache License

public BusinessSubscription(@Nullable final Plan currentPlan, @Nullable final PlanPhase currentPhase,
        @Nullable final PriceList priceList, final Currency currency, final DateTime startDate,
        final SubscriptionState state) {
    // TODO//from w w  w  . j  a v  a 2  s  .c  o m
    businessActive = true;

    this.priceList = priceList == null ? null : priceList.getName();

    // Record plan information
    if (currentPlan != null && currentPlan.getProduct() != null) {
        final Product product = currentPlan.getProduct();
        productName = product.getName();
        productCategory = product.getCategory().toString();
        productType = product.getCatalogName();
    } else {
        productName = null;
        productCategory = null;
        productType = null;
    }

    // Record phase information
    if (currentPhase != null) {
        slug = currentPhase.getName();

        if (currentPhase.getPhaseType() != null) {
            phase = currentPhase.getPhaseType().toString();
        } else {
            phase = null;
        }

        if (currentPhase.getBillingPeriod() != null) {
            billingPeriod = currentPhase.getBillingPeriod().toString();
        } else {
            billingPeriod = null;
        }

        if (currentPhase.getRecurringPrice() != null) {
            BigDecimal tmpPrice;
            try {
                tmpPrice = currentPhase.getRecurringPrice().getPrice(USD);
            } catch (CatalogApiException e) {
                tmpPrice = null;
            }

            price = tmpPrice;
            if (tmpPrice != null) {
                mrr = getMrrFromBillingPeriod(currentPhase.getBillingPeriod(), price);
            } else {
                mrr = null;
            }
        } else {
            price = null;
            mrr = null;
        }
    } else {
        slug = null;
        phase = null;
        billingPeriod = null;
        price = null;
        mrr = null;
    }

    if (currency != null) {
        this.currency = currency.toString();
    } else {
        this.currency = null;
    }

    this.startDate = startDate;
    if (currentPhase != null) {
        final Duration duration = currentPhase.getDuration();
        this.endDate = duration == null ? null : startDate.plus(duration.toJodaPeriod());
    } else {
        this.endDate = null;
    }
    this.state = state == null ? null : state.toString();
}

From source file:com.ning.billing.util.clock.OldClockMock.java

License:Apache License

private DateTime adjustFromDuration(final DateTime input) {

    DateTime result = input;
    for (final Duration cur : deltaFromRealityDuration) {
        switch (cur.getUnit()) {
        case DAYS:
            result = result.plusDays(cur.getNumber());
            break;

        case MONTHS:
            result = result.plusMonths(cur.getNumber());
            break;

        case YEARS:
            result = result.plusYears(cur.getNumber());
            break;

        case UNLIMITED:
        default://from   www.j a v a2 s. co  m
            throw new RuntimeException("ClockMock is adjusting an unlimited time period");
        }
    }
    if (deltaFromRealityDurationEpsilon != 0) {
        result = result.plus(deltaFromRealityDurationEpsilon);
    }
    return result;
}

From source file:com.ning.billing.util.clock.OldClockMock.java

License:Apache License

private DateTime adjustFromAbsolute(final DateTime input) {
    return truncateMs(input.plus(deltaFromRealityMs));
}

From source file:com.nominanuda.springmvc.AppControlHandler.java

License:Apache License

public synchronized void handleRequest(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {
    try {/*w w w.ja  va  2  s.  c  om*/
        Thread.sleep(1000);
        String appCommand = req.getParameter("cmd");
        String tsStr = req.getParameter("ts");
        String digest = req.getParameter("digest");
        Check.illegalargument
                .assertTrue(digest.equals(digester.hmacSHA256(appCommand + tsStr).toBase64Classic()));
        DateTime ts = isoFmt.parseDateTime(tsStr);
        Check.illegalargument.assertTrue(ts.plus(timestampValidityMillis).isAfter(new DateTime()));
        if ("refresh_appctx".equals(appCommand)) {
            ((AbstractApplicationContext) applicationContext).refresh();
            res.setContentType(HttpProtocol.CT_TEXT_PLAIN_CS_UTF8);
            res.setContentLength(okMsg.length);
            res.getWriter().write(okMsg);
        } else {
            Check.illegalargument.fail();
        }
    } catch (Exception e) {
        res.setStatus(400);
        res.setContentType(HttpProtocol.CT_TEXT_PLAIN_CS_UTF8);
        res.setContentLength(badReqMsg.length);
        res.getWriter().write(badReqMsg);
    }
}

From source file:com.pureblue.quant.util.frequency.CustomFrequency.java

@Override
public DateTime periodBegin(DateTime time) { // TODO: improve efficiency by removing the while loops
    DateTime currentTime = startTime;
    if (time.isAfter(startTime)) {
        while (!currentTime.isAfter(time)) {
            currentTime = currentTime.plus(duration);
        }/* w w  w.java 2s  .c  o m*/
        return currentTime.minus(duration);
    } else {
        while (currentTime.isAfter(time)) {
            currentTime = currentTime.minus(duration);
        }
        return currentTime;
    }
}

From source file:com.quant.TimeSeries.java

License:Open Source License

/**
 * Returns a new time series which is a view of a subset of the current series.
 * <p>/*from ww  w  . j a  va 2 s  .c  om*/
 * The new series has begin and end indexes which correspond to the bounds of the sub-set into the full series.<br>
 * The tick of the series are shared between the original time series and the returned one (i.e. no copy).
 * @param beginIndex the begin index (inclusive) of the time series
 * @param duration the duration of the time series
 * @return a constrained {@link TimeSeries time series} which is a sub-set of the current series
 */
public TimeSeries subseries(int beginIndex, Period duration) {

    // Calculating the sub-series interval
    DateTime beginInterval = getTick(beginIndex).getEndTime();
    DateTime endInterval = beginInterval.plus(duration);
    Interval subseriesInterval = new Interval(beginInterval, endInterval);

    // Checking ticks belonging to the sub-series (starting at the provided index)
    int subseriesNbTicks = 0;
    for (int i = beginIndex; i <= endIndex; i++) {
        // For each tick...
        DateTime tickTime = getTick(i).getEndTime();
        if (!subseriesInterval.contains(tickTime)) {
            // Tick out of the interval
            break;
        }
        // Tick in the interval
        // --> Incrementing the number of ticks in the subseries
        subseriesNbTicks++;
    }

    return subseries(beginIndex, beginIndex + subseriesNbTicks - 1);
}