From ebeedc148cde7022af92516fec64bf183b5eee61 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Wed, 10 Aug 2005 21:55:09 +0000 Subject: [PATCH] Added new attempt to parse the date. SMACK-67 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2523 b35dd754-fafc-0310-a699-88a17e54d16e --- .../provider/DelayInformationProvider.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java index 13e731fb7..2065af6fe 100644 --- a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java +++ b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java @@ -26,18 +26,21 @@ import org.jivesoftware.smackx.packet.DelayInformation; import org.xmlpull.v1.XmlPullParser; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; /** * The DelayInformationProvider parses DelayInformation packets. - * + * * @author Gaston Dombiak */ public class DelayInformationProvider implements PacketExtensionProvider { /** * Creates a new DeliveryInformationProvider. - * ProviderManager requires that every PacketExtensionProvider has a public, no-argument constructor + * ProviderManager requires that every PacketExtensionProvider has a public, no-argument + * constructor */ public DelayInformationProvider() { } @@ -49,7 +52,15 @@ public class DelayInformationProvider implements PacketExtensionProvider { } catch (ParseException e) { // Try again but assuming that the date follows JEP-82 format // (Jabber Date and Time Profiles) - stamp = DelayInformation.NEW_UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); + try { + stamp = DelayInformation.NEW_UTC_FORMAT + .parse(parser.getAttributeValue("", "stamp")); + } catch (ParseException e1) { + // Last attempt. Try parsing the date assuming that it does not include milliseconds + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + stamp = formatter.parse(parser.getAttributeValue("", "stamp")); + } } DelayInformation delayInformation = new DelayInformation(stamp); delayInformation.setFrom(parser.getAttributeValue("", "from"));