Commit 51cec23c authored by Leon Roy's avatar Leon Roy Committed by leonroy

OF-646 - XmppDateTimeFormat is unable to parse date Strings

XmppDateTimeFormat fix is pending in 3.8.2 and consequently XEP-0136 commands won't work with Openfire versions < 3.8.2. Have to revert this back to original state so that installations of Openfire prior to 3.8.2 can be supported. 

Will change it back to use org.jivesoftware.util.XmppDateTimeFormat at some point in the near future.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13628 b35dd754-fafc-0310-a699-88a17e54d16e
parent 584973dd
package com.reucon.openfire.plugin.archive.util;
import org.jivesoftware.util.XMPPDateTimeFormat;
import org.jivesoftware.util.JiveConstants;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Utility class to parse and format dates in UTC that adhere to the DateTime format specified
* in Jabber Date and Time Profiles.
* Utility class to parse and format dates in UTC that adhere to the DateTime format specified in Jabber Date and Time Profiles.
*/
public class XmppDateUtil
{
private static final XMPPDateTimeFormat xmppDateTime = new XMPPDateTimeFormat();
public static Date parseDate(String dateString)
{
try {
return xmppDateTime.parseString(dateString);
} catch (ParseException e) {
return null;
}
}
public static String formatDate(Date date)
{
if (date == null)
{
return null;
}
return XMPPDateTimeFormat.format(date);
}
public class XmppDateUtil {
private static final DateFormat dateFormat;
private static final DateFormat dateFormatWithoutMillis;
static {
dateFormat = new SimpleDateFormat(JiveConstants.XMPP_DATETIME_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
dateFormatWithoutMillis = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
dateFormatWithoutMillis.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private XmppDateUtil() {
}
public static Date parseDate(String dateString) {
Date date = null;
if (dateString == null) {
return null;
}
synchronized (dateFormat) {
try {
date = dateFormat.parse(dateString);
} catch (ParseException e) {
// ignore
}
}
if (date != null) {
return date;
}
synchronized (dateFormatWithoutMillis) {
try {
date = dateFormatWithoutMillis.parse(dateString);
} catch (ParseException e) {
// ignore
}
}
return date;
}
public static String formatDate(Date date) {
if (date == null) {
return null;
}
synchronized (dateFormat) {
return dateFormat.format(date);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment