Commit 46fca6b5 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Time formatting fixes for JM-310.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1715 b35dd754-fafc-0310-a699-88a17e54d16e
parent 71163d00
......@@ -15,19 +15,17 @@ import org.jivesoftware.messenger.disco.ServerFeaturesProvider;
import org.jivesoftware.messenger.IQHandlerInfo;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import java.util.*;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.xmpp.packet.IQ;
/**
* Implements the TYPE_IQ jabber:iq:time protocol (time info). Allows
* Jabber entities to query each other's local time. The server
* will respond with its local time.
* Implements the TYPE_IQ jabber:iq:time protocol (time info) as
* as defined by JEP-0090. Allows Jabber entities to query each
* other's local time. The server will respond with its local time.
* <p/>
* <h2>Assumptions</h2>
* This handler assumes that the time request is addressed to itself.
......@@ -45,6 +43,16 @@ import org.xmpp.packet.IQ;
*/
public class IQTimeHandler extends IQHandler implements ServerFeaturesProvider {
// todo Make display text match the locale of user (xml:lang support)
private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.MEDIUM);
private static final DateFormat TIME_FORMAT = DateFormat.getTimeInstance(DateFormat.LONG);
// UTC and not JEP-0082 time format is used as per the JEP-0090 specification.
private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
static {
UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}
private Element responseElement;
private IQHandlerInfo info;
......@@ -78,26 +86,11 @@ public class IQTimeHandler extends IQHandler implements ServerFeaturesProvider {
return response;
}
// todo Make display text match the locale of user (xml:lang support)
// #################################################################
// Standard formatting according to locale and Jabber specs
// #################################################################
private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.MEDIUM);
private static final DateFormat TIME_FORMAT = DateFormat.getTimeInstance(DateFormat.LONG);
private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
static {
UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
}
public IQHandlerInfo getInfo() {
return info;
}
public Iterator getFeatures() {
ArrayList features = new ArrayList();
features.add("jabber:iq:time");
return features.iterator();
return Collections.singleton("jabber:iq:time").iterator();
}
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import java.util.TimeZone;
import org.jivesoftware.messenger.muc.spi.MUCRoleImpl;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveConstants;
import org.dom4j.Element;
import org.xmpp.packet.Message;
......@@ -39,7 +40,7 @@ import org.xmpp.packet.Message;
*/
public class HistoryRequest {
private static final DateFormat formatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
private static final DateFormat formatter = new SimpleDateFormat(JiveConstants.XMPP_DATETIME_FORMAT);
private static final DateFormat delayedFormatter = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
static {
delayedFormatter.setTimeZone(TimeZone.getTimeZone("GMT+0"));
......
......@@ -26,4 +26,11 @@ public class JiveConstants {
public static final long HOUR = 60 * MINUTE;
public static final long DAY = 24 * HOUR;
public static final long WEEK = 7 * DAY;
/**
* Date/time format for use by SimpleDateFormat. The format conforms to
* <a href="http://www.jabber.org/jeps/jep-0082.html">JEP-0082</a>, which defines
* a unified date/time format for XMPP.
*/
public static final String XMPP_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
}
\ No newline at end of file
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