]> git.basschouten.com Git - openhab-addons.git/commitdiff
Fixed wrong time parsing (#10523)
authorChristoph Weitkamp <github@christophweitkamp.de>
Thu, 15 Apr 2021 15:45:48 +0000 (17:45 +0200)
committerGitHub <noreply@github.com>
Thu, 15 Apr 2021 15:45:48 +0000 (17:45 +0200)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.tr064/src/main/java/org/openhab/binding/tr064/internal/soap/CallListEntry.java

index 4bc9839a1d278bf843bb872e57a4e3daff63f01a..d782310b8f301b062778660b6d0ef6fa84f5f555 100644 (file)
  */
 package org.openhab.binding.tr064.internal.soap;
 
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
 import java.util.Date;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -28,7 +30,7 @@ import org.openhab.binding.tr064.internal.dto.additions.Call;
  */
 @NonNullByDefault
 public class CallListEntry {
-    private static final SimpleDateFormat DATE_FORMAT_PARSER = new SimpleDateFormat("dd.MM.yy hh:mm");
+    private static final DateTimeFormatter DATE_FORMAT_PARSER = DateTimeFormatter.ofPattern("dd.MM.yy HH:mm");
     public @Nullable String localNumber;
     public @Nullable String remoteNumber;
     public @Nullable Date date;
@@ -37,8 +39,9 @@ public class CallListEntry {
 
     public CallListEntry(Call call) {
         try {
-            date = DATE_FORMAT_PARSER.parse(call.getDate());
-        } catch (ParseException e) {
+            date = Date.from(
+                    LocalDateTime.parse(call.getDate(), DATE_FORMAT_PARSER).atZone(ZoneId.systemDefault()).toInstant());
+        } catch (DateTimeParseException e) {
             // ignore parsing error
             date = null;
         }