List of usage examples for java.time ZonedDateTime plusMinutes
public ZonedDateTime plusMinutes(long minutes)
From source file:org.openhab.binding.darksky.internal.handler.DarkSkyWeatherAndForecastHandler.java
/** * Applies the given configuration to the given timestamp. * * @param dateTime timestamp represented as {@link ZonedDateTime} * @param config {@link DarkSkyChannelConfiguration} instance * @return the modified timestamp/*from ww w . j a va 2 s .c o m*/ */ private ZonedDateTime applyChannelConfig(ZonedDateTime dateTime, @Nullable DarkSkyChannelConfiguration config) { ZonedDateTime modifiedDateTime = dateTime; if (config != null) { if (config.getOffset() != 0) { if (logger.isTraceEnabled()) { logger.trace("Apply offset of {} min to timestamp '{}'.", config.getOffset(), modifiedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } modifiedDateTime = modifiedDateTime.plusMinutes(config.getOffset()); } long earliestInMinutes = config.getEarliestInMinutes(); if (earliestInMinutes > 0) { ZonedDateTime earliestDateTime = modifiedDateTime.truncatedTo(ChronoUnit.DAYS) .plusMinutes(earliestInMinutes); if (modifiedDateTime.isBefore(earliestDateTime)) { if (logger.isTraceEnabled()) { logger.trace("Use earliest timestamp '{}' instead of '{}'.", earliestDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), modifiedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } return earliestDateTime; } } long latestInMinutes = config.getLatestInMinutes(); if (latestInMinutes > 0) { ZonedDateTime latestDateTime = modifiedDateTime.truncatedTo(ChronoUnit.DAYS) .plusMinutes(latestInMinutes); if (modifiedDateTime.isAfter(latestDateTime)) { if (logger.isTraceEnabled()) { logger.trace("Use latest timestamp '{}' instead of '{}'.", latestDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME), modifiedDateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)); } return latestDateTime; } } } return modifiedDateTime; }