mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for MQTT
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
d001636a5f
commit
cb74dd6497
@ -12,6 +12,8 @@
|
||||
*/
|
||||
package org.openhab.binding.mqtt.generic.values;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@ -45,11 +47,12 @@ public class DateTimeValue extends Value {
|
||||
|
||||
@Override
|
||||
public String getMQTTpublishValue(Command command, @Nullable String pattern) {
|
||||
ZonedDateTime zonedDateTime = ((DateTimeType) command).getZonedDateTime(ZoneId.systemDefault());
|
||||
String formatPattern = pattern;
|
||||
if (formatPattern == null || "%s".contentEquals(formatPattern)) {
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(((DateTimeType) command).getZonedDateTime());
|
||||
return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(zonedDateTime);
|
||||
}
|
||||
return String.format(formatPattern, ((DateTimeType) command).getZonedDateTime());
|
||||
return String.format(formatPattern, zonedDateTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user