Example usage for java.time ZonedDateTime until

List of usage examples for java.time ZonedDateTime until

Introduction

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

Prototype

@Override
public long until(Temporal endExclusive, TemporalUnit unit) 

Source Link

Document

Calculates the amount of time until another date-time in terms of the specified unit.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime dateTime = ZonedDateTime.now();
    long o = dateTime.until(ZonedDateTime.now(), ChronoUnit.YEARS);
    System.out.println(o);/*from w ww.  j  av  a  2  s .  c  o m*/
}

From source file:ru.jts_dev.gameserver.time.GameTimeService.java

public long minutesPassedSinceDayBeginning() {
    final ZonedDateTime dayBeginning = dateTime.with(LocalTime.MIN);
    return dayBeginning.until(dateTime, ChronoUnit.MINUTES);
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected long calculateSearchDelay(ZonedDateTime startTime) {
    long searchDelay = 0;

    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    ZonedDateTime offsetStartTime = startTime.plusSeconds(SEARCH_START_DELAY_SECONDS);

    if (now.isBefore(offsetStartTime)) {
        searchDelay = now.until(offsetStartTime, ChronoUnit.MILLIS);
    }//from ww  w .  j  ava 2s . c  o  m

    return searchDelay;
}

From source file:org.openhab.binding.buienradar.internal.BuienradarHandler.java

private void refresh() {
    try {//from  www .  j a v  a 2 s . c  o m
        @SuppressWarnings("null")
        final List<Prediction> predictions = client.getPredictions(location);
        for (final Prediction prediction : predictions) {
            final BigDecimal intensity = prediction.getIntensity();
            final ZonedDateTime nowPlusThree = ZonedDateTime.now().plusMinutes(3);
            final ZonedDateTime lastFiveMinute = nowPlusThree.withMinute((nowPlusThree.getMinute() / 5) * 5)
                    .withSecond(0).withNano(0);
            final long minutesFromNow = lastFiveMinute.until(prediction.getDateTime(), ChronoUnit.MINUTES);
            final long minuteClass = minutesFromNow;
            logger.debug("Forecast for {} at {} is {}", minutesFromNow, prediction.getDateTime(), intensity);
            if (minuteClass >= 0 && minuteClass <= 115) {
                final String label = String.format(Locale.ENGLISH, "forecast_%d", minuteClass);

                /** @TODO: edejong 2019-04-03 Change to SmartHomeUnits.MILLIMETRE_PER_HOUR for OH 2.5 */
                updateState(label, new QuantityType<Speed>(intensity, MILLIMETRE_PER_HOUR));
            }
        }

        updateStatus(ThingStatus.ONLINE);
    } catch (IOException e) {
        logger.warn("Cannot retrieve predictions", e);
        updateStatus(ThingStatus.ONLINE, ThingStatusDetail.COMMUNICATION_ERROR,
                String.format("Could not reach buienradar: %s", e.getMessage()));
    }
}