List of usage examples for java.time OffsetDateTime plus
@Override public OffsetDateTime plus(long amountToAdd, TemporalUnit unit)
From source file:Main.java
public static void main(String[] args) { OffsetDateTime o = OffsetDateTime.now(); OffsetDateTime d = o.plus(20, ChronoUnit.HOURS); System.out.println(d);/*from w ww.jav a2s . c o m*/ }
From source file:org.openmhealth.data.generator.service.TimestampedValueGroupGenerationServiceImpl.java
@Override public Iterable<TimestampedValueGroup> generateValueGroups(MeasureGenerationRequest request) { ExponentialDistribution interPointDurationDistribution = new ExponentialDistribution( request.getMeanInterPointDuration().getSeconds()); long totalDurationInS = Duration.between(request.getStartDateTime(), request.getEndDateTime()).getSeconds(); OffsetDateTime effectiveDateTime = request.getStartDateTime(); List<TimestampedValueGroup> timestampedValueGroups = new ArrayList<>(); do {//from ww w . j av a 2 s. com effectiveDateTime = effectiveDateTime.plus((long) interPointDurationDistribution.sample(), SECONDS); if (!effectiveDateTime.isBefore(request.getEndDateTime())) { break; } if (request.isSuppressNightTimeMeasures() != null && request.isSuppressNightTimeMeasures() && (effectiveDateTime.getHour() >= NIGHT_TIME_START_HOUR || effectiveDateTime.getHour() < NIGHT_TIME_END_HOUR)) { continue; } TimestampedValueGroup valueGroup = new TimestampedValueGroup(); valueGroup.setTimestamp(effectiveDateTime); double trendProgressFraction = (double) Duration.between(request.getStartDateTime(), effectiveDateTime) .getSeconds() / totalDurationInS; for (Map.Entry<String, BoundedRandomVariableTrend> trendEntry : request.getTrends().entrySet()) { String key = trendEntry.getKey(); BoundedRandomVariableTrend trend = trendEntry.getValue(); double value = trend.nextValue(trendProgressFraction); valueGroup.setValue(key, value); } timestampedValueGroups.add(valueGroup); } while (true); return timestampedValueGroups; }