From e17b75511e7c9d8206939b742972021c5c9d6b86 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 31 Mar 2015 16:30:47 +0200 Subject: timestamp parsing reverted --- .../siacs/conversations/parser/AbstractParser.java | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java index 977062e2..473195bd 100644 --- a/src/main/java/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/main/java/eu/siacs/conversations/parser/AbstractParser.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.parser; +import android.util.Log; + import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -41,8 +43,14 @@ public abstract class AbstractParser { if (stamp == null) { return now; } - long time = parseTimestamp(stamp).getTime(); - return now < time ? now : time; + /*long time = parseTimestamp(stamp).getTime(); + return now < time ? now : time;*/ + try { + long time = parseTimestamp(stamp).getTime(); + return now < time ? now : time; + } catch (ParseException e) { + return now; + } } /** @@ -53,12 +61,19 @@ public abstract class AbstractParser { * @return Date * @throws ParseException */ - public static Date parseTimestamp(String timestamp) { - try { + public static Date parseTimestamp(String timestamp) throws ParseException { + /*try { + Log.d("TIMESTAMP", timestamp); return DatatypeFactory.newInstance().newXMLGregorianCalendar(timestamp).toGregorianCalendar().getTime(); } catch (DatatypeConfigurationException e) { + Log.d("TIMESTAMP", e.getMessage()); return new Date(); - } + }*/ + timestamp = timestamp.replace("Z", "+0000"); + SimpleDateFormat dateFormat; + timestamp = timestamp.substring(0,19)+timestamp.substring(timestamp.length() -5,timestamp.length()); + dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",Locale.US); + return dateFormat.parse(timestamp); } protected void updateLastseen(final Element packet, final Account account, -- cgit v1.2.3