Smack

org.jivesoftware.smackx.packet
Class Time

java.lang.Object
  extended by org.jivesoftware.smack.packet.Packet
      extended by org.jivesoftware.smack.packet.IQ
          extended by org.jivesoftware.smackx.packet.Time

public class Time
extends IQ

A Time IQ packet, which is used by XMPP clients to exchange their respective local times. Clients that wish to fully support the entitity time protocol should register a PacketListener for incoming time requests that then respond with the local time. This class can be used to request the time from other clients, such as in the following code snippet:

 // Request the time from a remote user.
 Time timeRequest = new Time();
 timeRequest.setType(IQ.Type.GET);
 timeRequest.setTo(someUser@example.com/resource);

 // Create a packet collector to listen for a response.
 PacketCollector collector = con.createPacketCollector(
                new PacketIDFilter(timeRequest.getPacketID()));

 con.sendPacket(timeRequest);

 // Wait up to 5 seconds for a result.
 IQ result = (IQ)collector.nextResult(5000);
 if (result != null && result.getType() == IQ.Type.RESULT) {
     Time timeResult = (Time)result;
     // Do something with result...
 }

Warning: this is an non-standard protocol documented by XEP-0090. Because this is a non-standard protocol, it is subject to change.

Author:
Matt Tucker

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jivesoftware.smack.packet.IQ
IQ.Type
 
Field Summary
 
Fields inherited from class org.jivesoftware.smack.packet.Packet
DEFAULT_LANGUAGE, ID_NOT_AVAILABLE
 
Constructor Summary
Time()
          Creates a new Time instance with empty values for all fields.
Time(java.util.Calendar cal)
          Creates a new Time instance using the specified calendar instance as the time value to send.
 
Method Summary
 java.lang.String getChildElementXML()
          Returns the sub-element XML section of the IQ packet, or null if there isn't one.
 java.lang.String getDisplay()
          Returns the local (non-utc) time in human-friendly format.
 java.util.Date getTime()
          Returns the local time or null if the time hasn't been set.
 java.lang.String getTz()
          Returns the time zone.
 java.lang.String getUtc()
          Returns the time as a UTC formatted String using the format CCYYMMDDThh:mm:ss.
 void setDisplay(java.lang.String display)
          Sets the local time in human-friendly format.
 void setTime(java.util.Date time)
          Sets the time using the local time.
 void setTz(java.lang.String tz)
          Sets the time zone.
 void setUtc(java.lang.String utc)
          Sets the time using UTC formatted String in the format CCYYMMDDThh:mm:ss.
 
Methods inherited from class org.jivesoftware.smack.packet.IQ
createErrorResponse, createResultIQ, getType, setType, toXML
 
Methods inherited from class org.jivesoftware.smack.packet.Packet
addExtension, addExtensions, deleteProperty, equals, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensionsXML, getFrom, getPacketID, getProperty, getPropertyNames, getTo, getXmlns, hashCode, nextID, removeExtension, setDefaultXmlns, setError, setFrom, setPacketID, setProperty, setTo
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Time

public Time()
Creates a new Time instance with empty values for all fields.


Time

public Time(java.util.Calendar cal)
Creates a new Time instance using the specified calendar instance as the time value to send.

Parameters:
cal - the time value.
Method Detail

getTime

public java.util.Date getTime()
Returns the local time or null if the time hasn't been set.

Returns:
the lcocal time.

setTime

public void setTime(java.util.Date time)
Sets the time using the local time.

Parameters:
time - the current local time.

getUtc

public java.lang.String getUtc()
Returns the time as a UTC formatted String using the format CCYYMMDDThh:mm:ss.

Returns:
the time as a UTC formatted String.

setUtc

public void setUtc(java.lang.String utc)
Sets the time using UTC formatted String in the format CCYYMMDDThh:mm:ss.

Parameters:
utc - the time using a formatted String.

getTz

public java.lang.String getTz()
Returns the time zone.

Returns:
the time zone.

setTz

public void setTz(java.lang.String tz)
Sets the time zone.

Parameters:
tz - the time zone.

getDisplay

public java.lang.String getDisplay()
Returns the local (non-utc) time in human-friendly format.

Returns:
the local time in human-friendly format.

setDisplay

public void setDisplay(java.lang.String display)
Sets the local time in human-friendly format.

Parameters:
display - the local time in human-friendly format.

getChildElementXML

public java.lang.String getChildElementXML()
Description copied from class: IQ
Returns the sub-element XML section of the IQ packet, or null if there isn't one. Packet extensions must be included, if any are defined.

Extensions of this class must override this method.

Specified by:
getChildElementXML in class IQ
Returns:
the child element section of the IQ XML.

Smack

Copyright © 2003-2007 Jive Software.