diff --git a/source/org/jivesoftware/smackx/packet/DelayInformation.java b/source/org/jivesoftware/smackx/packet/DelayInformation.java index 453ff1500..e9e90331a 100644 --- a/source/org/jivesoftware/smackx/packet/DelayInformation.java +++ b/source/org/jivesoftware/smackx/packet/DelayInformation.java @@ -22,6 +22,7 @@ package org.jivesoftware.smackx.packet; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; import org.jivesoftware.smack.packet.PacketExtension; @@ -38,6 +39,18 @@ import org.jivesoftware.smack.packet.PacketExtension; public class DelayInformation implements PacketExtension { public static SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss"); + /** + * New date format based on JEP-82 that some clients may use when sending delayed dates. + * JEP-91 is using a SHOULD other servers or clients may be using this format instead of the + * old UTC format. + */ + public static SimpleDateFormat NEW_UTC_FORMAT = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + + static { + UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0")); + NEW_UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); + } private Date stamp; private String from; diff --git a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java index 80f24be0a..13e731fb7 100644 --- a/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java +++ b/source/org/jivesoftware/smackx/provider/DelayInformationProvider.java @@ -20,14 +20,14 @@ package org.jivesoftware.smackx.provider; -import java.util.Date; -import java.util.TimeZone; - import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.provider.PacketExtensionProvider; import org.jivesoftware.smackx.packet.DelayInformation; import org.xmlpull.v1.XmlPullParser; +import java.text.ParseException; +import java.util.Date; + /** * The DelayInformationProvider parses DelayInformation packets. * @@ -43,8 +43,14 @@ public class DelayInformationProvider implements PacketExtensionProvider { } public PacketExtension parseExtension(XmlPullParser parser) throws Exception { - DelayInformation.UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0")); - Date stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); + Date stamp = null; + try { + stamp = DelayInformation.UTC_FORMAT.parse(parser.getAttributeValue("", "stamp")); + } 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")); + } DelayInformation delayInformation = new DelayInformation(stamp); delayInformation.setFrom(parser.getAttributeValue("", "from")); delayInformation.setReason(parser.nextText());