public void processPacket(Packet message) {
if (!(message instanceof Time)
|| ((IQ) message).getType() != IQ.Type.GET)
return;
Time time = (Time) message;
String from = message.getFrom();
String to = message.getTo();
com.valhalla.Logger.debug("Time request received from " + from);
Calendar cal = Calendar.getInstance();
SimpleDateFormat utcFormat = new SimpleDateFormat("yyyyMMdd'T'hh:mm:ss");
DateFormat displayFormat = DateFormat.getDateTimeInstance();
TimeZone timeZone = cal.getTimeZone();
time.setTz(cal.getTimeZone().getID());
time.setDisplay(displayFormat.format(cal.getTime()));
// Convert local time to the UTC time.
time.setUtc(utcFormat.format(new Date(cal.getTimeInMillis()
- timeZone.getOffset(cal.getTimeInMillis()))));
time.setTo(from);
time.setFrom(to);
time.setType(IQ.Type.RESULT);
// send the response
if (BuddyList.getInstance().checkConnection())
BuddyList.getInstance().getConnection().sendPacket(time);
}