List of usage examples for java.time ZonedDateTime withMinute
public ZonedDateTime withMinute(int minute)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.now(); ZonedDateTime n = dateTime.withMinute(14); System.out.println(n);//from w w w.j a va2 s. c o m }
From source file:org.openhab.binding.buienradar.internal.BuienradarHandler.java
private void refresh() { try {//from w w w . ja v a 2 s . c om @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())); } }
From source file:org.qcert.camp.translator.SemRule2CAMP.java
/** * Incomplete but evolving translation for object allocations involving temporal constructs * @param ast the object allocation (SemNewObject) * @return the translation/*from ww w .j a v a2 s .co m*/ */ private CampPattern translateTemporalAllocation(SemNewObject ast) { List<SemValue> args = ast.getArguments(); if (DATE_TYPE.equals(ast.getType().getDisplayName())) { Iterator<SemValue> argIter = args.iterator(); ZonedDateTime translation = ZonedDateTime.ofInstant(Instant.EPOCH, ZoneId.systemDefault()) .withYear(intFrom(argIter.next())).withMonth(intFrom(argIter.next())) .withDayOfMonth(intFrom(argIter.next())); if (argIter.hasNext()) translation = translation.withHour(intFrom(argIter.next())); if (argIter.hasNext()) translation = translation.withMinute(intFrom(argIter.next())); if (argIter.hasNext()) translation = translation.withSecond(intFrom(argIter.next())); ConstPattern constant = new ConstPattern(translation.toString()); return new UnaryPattern(UnaryOperator.ATimeFromString, constant); } if (TIME_TYPE.equals(ast.getType().getDisplayName()) && args.size() == 1) { long epochMilli = longFrom(args.get(0)); LocalTime translation = ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMilli), ZoneOffset.UTC) .toLocalTime(); // TODO this should really be a unique CAMP type corresponding to the TTRL type for LocalTimeComponentValue return new ConstPattern(translation.toString()); } return notImplemented("Translation of temporal allocation: " + ast); }