Fixed wrong time parsing (#10523)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/10528/head
Christoph Weitkamp 2021-04-15 17:45:48 +02:00 committed by GitHub
parent 0c36650179
commit 7dad6ea973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -12,8 +12,10 @@
*/
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;
}