Example usage for org.joda.time LocalDateTime withPeriodAdded

List of usage examples for org.joda.time LocalDateTime withPeriodAdded

Introduction

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

Prototype

public LocalDateTime withPeriodAdded(ReadablePeriod period, int scalar) 

Source Link

Document

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

Usage

From source file:eu.trentorise.game.model.PointConcept.java

License:Apache License

/**
 * The method returns the PeriodInstance relative to the index.
 * //from   w ww . j  a va 2  s  .c o  m
 * @param periodIdentifier
 *            identifier of period
 * @param instanceIndex
 *            index of instance
 * @return PeriodInstance bound to the index or null if there is not
 *         PeriodInstance at that index
 */
public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) {
    PeriodInstance result = null;
    PeriodInternal p = periods.get(periodIdentifier);
    if (p != null) {
        if (p.period == -1 && instanceIndex > 0) {
            result = new PeriodInstanceImpl(p.getEnd().map(e -> e.getTime()).orElse(-1L), -1L);
        } else {
            LocalDateTime dateCursor = new LocalDateTime(p.start);
            dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex);
            result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime());
        }
    }

    return result;
}

From source file:it.smartcommunitylab.climb.domain.model.gamification.PointConcept.java

License:Apache License

/**
 * The method returns the PeriodInstance relative to the index.
 * /*from   w w w.  j a v a  2 s  .c  o m*/
 * @param periodIdentifier
 *            identifier of period
 * @param instanceIndex
 *            index of instance
 * @return PeriodInstance bound to the index or null if there is not
 *         PeriodInstance at that index
 */
public PeriodInstance getPeriodInstance(String periodIdentifier, int instanceIndex) {
    PeriodInstance result = null;
    PeriodInternal p = periods.get(periodIdentifier);
    if (p != null) {
        LocalDateTime dateCursor = new LocalDateTime(p.start);
        dateCursor = dateCursor.withPeriodAdded(new org.joda.time.Period(p.period), instanceIndex);
        result = getPeriodInstance(periodIdentifier, dateCursor.toDate().getTime());
    }

    return result;
}