mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 08:12: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:
parent
69c86bbeec
commit
ebeedc148c
1 changed files with 14 additions and 3 deletions
|
@ -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"));
|
||||
|
|
Loading…
Reference in a new issue