1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

Improved parsing of date considering JEP-82 format. SMACK-67

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2516 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-07-28 00:42:29 +00:00 committed by gaston
parent 1ce0be62d0
commit 34baa2545b
2 changed files with 24 additions and 5 deletions

View file

@ -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;

View file

@ -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());