Example usage for java.time ZonedDateTime plus

List of usage examples for java.time ZonedDateTime plus

Introduction

In this page you can find the example usage for java.time ZonedDateTime plus.

Prototype

@Override
public ZonedDateTime plus(long amountToAdd, TemporalUnit unit) 

Source Link

Document

Returns a copy of this date-time with the specified amount added.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    ZonedDateTime n = dateTime.plus(12, ChronoUnit.YEARS);
    System.out.println(n);/* www  .  j  av  a 2 s  .c  o m*/
}

From source file:com.example.app.support.service.AppUtil.java

/**
 * Get a ZonedDateTime for comparison on membership dates
 *
 * @param zone the TimeZone/*from  ww w .  j  a v a 2s  .  co m*/
 *
 * @return the ZonedDateTime
 */
public static ZonedDateTime getZonedDateTimeForComparison(TimeZone zone) {
    ZonedDateTime dt = ZonedDateTime.now(zone.toZoneId());
    dt = dt.plus(1L, ChronoUnit.HOURS);
    dt = dt.truncatedTo(ChronoUnit.HOURS);
    return dt;
}

From source file:com.yahoo.egads.models.tsmm.OlympicModel2.java

@Override
public void train(final DataSequence data) throws Exception {
    initializeIndices(data, modelStartEpoch);

    final long size = data.size();
    ZonedDateTime model_ts = Instant.ofEpochSecond(modelStartEpoch).atZone(zone);
    ZonedDateTime end_ts = model_ts.plus(windowSize, windowUnits);
    int prediction_index = 0;
    final List<WeightedValue> accumulator = Lists.newArrayList();

    // start the loop and break once we've filled the model.
    while (true) {
        accumulator.clear();//from   w  w  w . j a  v a2s. c o m
        for (int i = 0; i < windowTimes.length; i++) {
            if (indices[i] < 0 || indices[i] >= size) {
                continue;
            }

            // advance
            windowTimes[i] = windowTimes[i].plus(interval, intervalUnits);
            long interval_end = windowTimes[i].toEpochSecond();
            final List<Double> doubles = Lists.newArrayList();
            long first_ts = -1;
            while (indices[i] < size && data.get(indices[i]).time < interval_end) {
                if (Double.isFinite(data.get(indices[i]).value)) {
                    doubles.add((double) data.get(indices[i]).value);
                }
                if (first_ts < 0) {
                    first_ts = data.get(indices[i]).time;
                }
                indices[i]++;
            }

            if (!doubles.isEmpty()) {
                // TODO - for DST if we jumped back then we may have a
                // period
                // with more than we expect. In that case, depending on the
                // aggregator, we may need to use only part of the data.
                // TODO - potentially other aggregations.
                double sum = 0;
                for (final Double v : doubles) {
                    sum += v;
                }
                accumulator.add(new WeightedValue((sum / doubles.size()), i + 1));
            }
        }

        if (drop_lowest > 0 || drop_highest > 0) {
            if (drop_highest > drop_lowest) {
                WeightedValue.drop(accumulator, drop_highest, true);
                WeightedValue.drop(accumulator, drop_lowest, false);
            } else {
                WeightedValue.drop(accumulator, drop_lowest, false);
                WeightedValue.drop(accumulator, drop_highest, true);
            }
        }

        model.add(new Pair<Long, Double>(model_ts.toEpochSecond(),
                WeightedValue.aggregate(accumulator, windowAggregator)));

        model_ts = model_ts.plus(interval, intervalUnits);
        if (model_ts.toEpochSecond() > end_ts.toEpochSecond()) {
            prediction_index++;
            if (prediction_index >= futureWindows) {
                break;
            }
            model_ts = Instant.ofEpochSecond(modelStartEpoch).atZone(zone);
            model_ts = model_ts.plus((windowDistanceInterval * prediction_index), windowDistanceIntervalUnits);
            end_ts = model_ts.plus(windowSize, windowUnits);
            for (int i = 0; i < windowTimes.length; i++) {
                windowTimes[i] = null;
                indices[i] = 0;
            }
            initializeIndices(data, model_ts.toEpochSecond());
        }
    }
}

From source file:at.ac.ait.ariadne.routeformat.example.IntermodalRouteExample.java

private IntermediateStop createIntermediateStopNeueDonau() {
    ZonedDateTime arrivalTime = ZonedDateTime.parse("2016-01-01T15:22:30+01:00");
    ZonedDateTime departureTime = arrivalTime.plus(60, ChronoUnit.SECONDS);
    return IntermediateStop.builder().withStop(neueDonauSubwayStop).withPlannedArrivalTime(arrivalTime)
            .withPlannedDepartureTime(departureTime).withEstimatedArrivalTime(arrivalTime)
            .withEstimatedDepartureTime(departureTime).build();
}

From source file:org.openhab.binding.amazonechocontrol.internal.handler.EchoHandler.java

public void updateNotifications(ZonedDateTime currentTime, ZonedDateTime now,
        @Nullable JsonCommandPayloadPushNotificationChange pushPayload,
        JsonNotificationResponse[] notifications) {
    Device device = this.device;
    if (device == null) {
        return;//ww  w .  j a v a 2 s .  com
    }

    ZonedDateTime nextReminder = null;
    ZonedDateTime nextAlarm = null;
    ZonedDateTime nextMusicAlarm = null;
    ZonedDateTime nextTimer = null;
    for (JsonNotificationResponse notification : notifications) {
        if (StringUtils.equals(notification.deviceSerialNumber, device.serialNumber)) {
            // notification for this device
            if (StringUtils.equals(notification.status, "ON")) {
                if ("Reminder".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextReminder == null || alarmTime.isBefore(nextReminder)) {
                        nextReminder = alarmTime;
                    }
                } else if ("Timer".equals(notification.type)) {
                    // use remaining time
                    ZonedDateTime alarmTime = currentTime.plus(notification.remainingTime, ChronoUnit.MILLIS);
                    if (nextTimer == null || alarmTime.isBefore(nextTimer)) {
                        nextTimer = alarmTime;
                    }
                } else if ("Alarm".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextAlarm == null || alarmTime.isBefore(nextAlarm)) {
                        nextAlarm = alarmTime;
                    }
                } else if ("MusicAlarm".equals(notification.type)) {
                    String offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()).toString();
                    ZonedDateTime alarmTime = ZonedDateTime
                            .parse(notification.originalDate + "T" + notification.originalTime + offset);
                    if (StringUtils.isNotBlank(notification.recurringPattern) && alarmTime.isBefore(now)) {
                        continue; // Ignore recurring entry if alarm time is before now
                    }
                    if (nextMusicAlarm == null || alarmTime.isBefore(nextMusicAlarm)) {
                        nextMusicAlarm = alarmTime;
                    }
                }
            }
        }
    }

    updateState(CHANNEL_NEXT_REMINDER, nextReminder == null ? UnDefType.UNDEF : new DateTimeType(nextReminder));
    updateState(CHANNEL_NEXT_ALARM, nextAlarm == null ? UnDefType.UNDEF : new DateTimeType(nextAlarm));
    updateState(CHANNEL_NEXT_MUSIC_ALARM,
            nextMusicAlarm == null ? UnDefType.UNDEF : new DateTimeType(nextMusicAlarm));
    updateState(CHANNEL_NEXT_TIMER, nextTimer == null ? UnDefType.UNDEF : new DateTimeType(nextTimer));
}

From source file:sorcer.file.ScratchDirManager.java

private boolean isCutoffTime(Path path, long cutOffTime) throws IOException {
    ZonedDateTime now = ZonedDateTime.now();
    BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
    ZonedDateTime created = ZonedDateTime.ofInstant(attrs.creationTime().toInstant(), now.getZone());

    created = created.withYear(now.getYear()).withMonth(now.getMonthValue());

    ZonedDateTime cutoff = created.plus(cutOffTime, MILLIS);

    log.info("Created {}", created);
    log.info("now     {}", now);
    log.info("cutoff  {}", cutoff);

    return now.isAfter(cutoff);
}