List of usage examples for java.time.zone ZoneRules getDaylightSavings
public Duration getDaylightSavings(Instant instant)
From source file:org.openhab.binding.airvisualnode.internal.handler.AirVisualNodeHandler.java
private State getChannelState(String channelId, NodeData nodeData) { State state = UnDefType.UNDEF; // Handle system channel IDs separately, because 'switch/case' expressions must be constant expressions if (CHANNEL_BATTERY_LEVEL.equals(channelId)) { state = new DecimalType(BigDecimal.valueOf(nodeData.getStatus().getBattery()).longValue()); } else if (CHANNEL_WIFI_STRENGTH.equals(channelId)) { state = new DecimalType( BigDecimal.valueOf(Math.max(0, nodeData.getStatus().getWifiStrength() - 1)).longValue()); } else {/* w w w . j a v a 2 s . c o m*/ // Handle binding-specific channel IDs switch (channelId) { case CHANNEL_CO2: state = new QuantityType<>(nodeData.getMeasurements().getCo2Ppm(), PARTS_PER_MILLION); break; case CHANNEL_HUMIDITY: state = new QuantityType<>(nodeData.getMeasurements().getHumidityRH(), PERCENT); break; case CHANNEL_AQI_US: state = new QuantityType<>(nodeData.getMeasurements().getPm25AQIUS(), ONE); break; case CHANNEL_PM_25: // PM2.5 is in ug/m3 state = new QuantityType<>(nodeData.getMeasurements().getPm25Ugm3(), MICRO(GRAM).divide(CUBIC_METRE)); break; case CHANNEL_TEMP_CELSIUS: state = new QuantityType<>(nodeData.getMeasurements().getTemperatureC(), CELSIUS); break; case CHANNEL_TIMESTAMP: // It seem the Node timestamp is Unix timestamp converted from UTC time plus timezone offset. // Not sure about DST though, but it's best guess at now Instant instant = Instant.ofEpochMilli(nodeData.getStatus().getDatetime() * 1000L); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")); ZoneId zoneId = ZoneId.of(nodeData.getSettings().getTimezone()); ZoneRules zoneRules = zoneId.getRules(); zonedDateTime.minus(Duration.ofSeconds(zoneRules.getOffset(instant).getTotalSeconds())); if (zoneRules.isDaylightSavings(instant)) { zonedDateTime.minus(Duration.ofSeconds(zoneRules.getDaylightSavings(instant).getSeconds())); } state = new DateTimeType(zonedDateTime); break; case CHANNEL_USED_MEMORY: state = new DecimalType(BigDecimal.valueOf(nodeData.getStatus().getUsedMemory()).longValue()); break; } } return state; }