Example usage for java.time OffsetDateTime plusMinutes

List of usage examples for java.time OffsetDateTime plusMinutes

Introduction

In this page you can find the example usage for java.time OffsetDateTime plusMinutes.

Prototype

public OffsetDateTime plusMinutes(long minutes) 

Source Link

Document

Returns a copy of this OffsetDateTime with the specified number of minutes added.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now();
    OffsetDateTime d = o.plusMinutes(20);
    System.out.println(d);/* ww w.j  av  a2  s .com*/
}

From source file:org.openmhealth.data.generator.service.AbstractDataPointGeneratorImpl.java

/**
 * @param measure a measure//from  ww w . ja  v  a  2 s.  c  om
 * @return a data point corresponding to the specified measure
 */
public DataPoint<T> newDataPoint(T measure) {

    TimeInterval effectiveTimeInterval = measure.getEffectiveTimeFrame().getTimeInterval();
    OffsetDateTime effectiveEndDateTime;

    if (effectiveTimeInterval != null) {
        if (effectiveTimeInterval.getEndDateTime() != null) {
            effectiveEndDateTime = effectiveTimeInterval.getEndDateTime();
        } else {
            // use the duration to calculate the end date time of the interval
            if (effectiveTimeInterval.getDuration() != null) {

                BiFunction<OffsetDateTime, Long, OffsetDateTime> plusFunction;

                switch (effectiveTimeInterval.getDuration().getTypedUnit()) {

                case SECOND:
                    plusFunction = OffsetDateTime::plusSeconds;
                    break;
                case MINUTE:
                    plusFunction = OffsetDateTime::plusMinutes;
                    break;
                case HOUR:
                    plusFunction = OffsetDateTime::plusHours;
                    break;
                case DAY:
                    plusFunction = OffsetDateTime::plusDays;
                    break;
                case WEEK:
                    plusFunction = OffsetDateTime::plusWeeks;
                    break;
                case MONTH:
                    plusFunction = OffsetDateTime::plusMonths;
                    break;
                case YEAR:
                    plusFunction = OffsetDateTime::plusYears;
                    break;
                default:
                    throw new IllegalStateException("A time interval duration type isn't supported.");
                }

                effectiveEndDateTime = plusFunction.apply(effectiveTimeInterval.getStartDateTime(),
                        effectiveTimeInterval.getDuration().getValue().longValue());
            } else {
                throw new IllegalStateException("An end date time can't be calculated without a duration.");
            }
        }
    } else { // if this is a point in time measure
        effectiveEndDateTime = measure.getEffectiveTimeFrame().getDateTime();
    }

    DataPointAcquisitionProvenance acquisitionProvenance = new DataPointAcquisitionProvenance.Builder(
            sourceName).setModality(SENSED).setSourceCreationDateTime(effectiveEndDateTime).build();

    DataPointHeader header = new DataPointHeader.Builder(randomUUID().toString(), measure.getSchemaId(),
            effectiveEndDateTime.plusMinutes(1)).setAcquisitionProvenance(acquisitionProvenance)
                    .setUserId(userId).build();

    return new DataPoint<>(header, measure);
}