1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 04:22:05 +01:00

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
This commit is contained in:
Gaston Dombiak 2005-08-10 21:55:09 +00:00 committed by gaston
parent 69c86bbeec
commit ebeedc148c

View file

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