diff --git a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java index 087f27c78..263060ebf 100644 --- a/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/callhistory/CallHistoryServiceImpl.java @@ -7,6 +7,7 @@ package net.java.sip.communicator.impl.callhistory; import java.io.*; +import java.text.*; import java.util.*; import net.java.sip.communicator.service.callhistory.*; @@ -380,6 +381,7 @@ static CallRecord convertHistoryRecordToCallRecord(HistoryRecord hr) // 4 - callParticipantStart // 5 - callParticipantEnd + SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); for (int i = 0; i < hr.getPropertyNames().length; i++) { String propName = hr.getPropertyNames()[i]; @@ -388,9 +390,23 @@ static CallRecord convertHistoryRecordToCallRecord(HistoryRecord hr) if (propName.equals(STRUCTURE_NAMES[0])) result.setProtocolProvider(getProtocolProvider(value)); else if(propName.equals(STRUCTURE_NAMES[1])) - result.setStartTime(new Date(Long.parseLong(value))); + try + { + result.setStartTime(sdf.parse(value)); + } + catch (ParseException e) + { + result.setStartTime(new Date(Long.parseLong(value))); + } else if(propName.equals(STRUCTURE_NAMES[2])) - result.setEndTime(new Date(Long.parseLong(value))); + try + { + result.setEndTime(sdf.parse(value)); + } + catch (ParseException e) + { + result.setEndTime(new Date(Long.parseLong(value))); + } else if(propName.equals(STRUCTURE_NAMES[3])) result.setDirection(value); else if(propName.equals(STRUCTURE_NAMES[4])) @@ -418,8 +434,15 @@ else if(propName.equals(STRUCTURE_NAMES[9])) if (i < callPeerStart.size()) { - callPeerStartValue - = new Date(Long.parseLong(callPeerStart.get(i))); + try + { + callPeerStartValue = sdf.parse(callPeerStart.get(i)); + } + catch (ParseException e) + { + callPeerStartValue + = new Date(Long.parseLong(callPeerStart.get(i))); + } } else { @@ -432,8 +455,15 @@ else if(propName.equals(STRUCTURE_NAMES[9])) if (i < callPeerEnd.size()) { - callPeerEndValue - = new Date(Long.parseLong(callPeerEnd.get(i))); + try + { + callPeerEndValue = sdf.parse(callPeerEnd.get(i)); + } + catch (ParseException e) + { + callPeerEndValue + = new Date(Long.parseLong(callPeerEnd.get(i))); + } } else { @@ -645,6 +675,8 @@ private void writeCall( CallRecordImpl callRecord, { try { + SimpleDateFormat sdf + = new SimpleDateFormat(HistoryService.DATE_FORMAT); History history = this.getHistory(source, destination); HistoryWriter historyWriter = history.getWriter(); @@ -668,18 +700,16 @@ private void writeCall( CallRecordImpl callRecord, callPeerIDs.append(item.getPeerAddress()); callPeerNames.append(item.getDisplayName()); - callPeerStartTime.append(String.valueOf(item - .getStartTime().getTime())); - callPeerEndTime.append(String.valueOf(item.getEndTime() - .getTime())); + callPeerStartTime.append(sdf.format(item.getStartTime())); + callPeerEndTime.append(sdf.format(item.getEndTime())); callPeerStates.append(item.getState().getStateString()); } historyWriter.addRecord(new String[] { callRecord.getSourceCall().getProtocolProvider() .getAccountID().getAccountUniqueID(), - String.valueOf(callRecord.getStartTime().getTime()), - String.valueOf(callRecord.getEndTime().getTime()), + sdf.format(callRecord.getStartTime()), + sdf.format(callRecord.getEndTime()), callRecord.getDirection(), callPeerIDs.toString(), callPeerStartTime.toString(), diff --git a/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java b/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java index a0b9e4ab4..e8b343b09 100644 --- a/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/filehistory/FileHistoryServiceImpl.java @@ -6,7 +6,11 @@ */ package net.java.sip.communicator.impl.filehistory; +import static + net.java.sip.communicator.service.history.HistoryService.DATE_FORMAT; + import java.io.*; +import java.text.*; import java.util.*; import net.java.sip.communicator.service.contactlist.*; @@ -227,10 +231,11 @@ private FileRecord createFileRecordFromHistoryRecord( { String file = null; String dir = null; - long date = 0; + Date date = new Date(0); String status = null; String id = null; + SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); for (int i = 0; i < hr.getPropertyNames().length; i++) { String propName = hr.getPropertyNames()[i]; @@ -243,11 +248,11 @@ else if (propName.equals(STRUCTURE_NAMES[2])) { try { - date = Long.valueOf(hr.getPropertyValues()[i]); + date = sdf.parse(hr.getPropertyValues()[i]); } - catch (NumberFormatException e) + catch (ParseException e) { - logger.error("Wrong date : " + hr.getPropertyValues()[i]); + date = new Date(Long.valueOf(hr.getPropertyValues()[i])); } } else if (propName.equals(STRUCTURE_NAMES[3])) @@ -760,10 +765,12 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event) History history = getHistory(null, req.getSender()); HistoryWriter historyWriter = history.getWriter(); + SimpleDateFormat sdf + = new SimpleDateFormat(HistoryService.DATE_FORMAT); historyWriter.addRecord(new String[]{ req.getFileName(), getDirection(FileTransfer.IN), - String.valueOf(event.getTimestamp().getTime()), + sdf.format(event.getTimestamp()), FILE_TRANSFER_ACTIVE, req.getID() }); @@ -799,10 +806,13 @@ public void fileTransferCreated(FileTransferCreatedEvent event) } else if (fileTransfer.getDirection() == FileTransfer.OUT) { + SimpleDateFormat sdf + = new SimpleDateFormat(HistoryService.DATE_FORMAT); + historyWriter.addRecord(new String[]{ fileTransfer.getLocalFile().getCanonicalPath(), getDirection(FileTransfer.OUT), - String.valueOf(event.getTimestamp().getTime()), + sdf.format(event.getTimestamp()), FILE_TRANSFER_ACTIVE, fileTransfer.getID() }); @@ -874,10 +884,10 @@ private static class FileRecordComparator { public int compare(FileRecord o1, FileRecord o2) { - long date1 = o1.getDate(); - long date2 = o2.getDate(); + Date date1 = o1.getDate(); + Date date2 = o2.getDate(); - return (date1 < date2) ? -1 : ((date1 == date2) ? 0 : 1); + return date1.compareTo(date2); } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationComponent.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationComponent.java index ec7cd405c..9f3a29a0c 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationComponent.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationComponent.java @@ -296,7 +296,7 @@ protected void openFile(File downloadFile) */ public String getDateString(Date date) { - return ChatHtmlUtils.getDateString(date.getTime()) + return ChatHtmlUtils.getDateString(date) + GuiUtils.formatTime(date) + " "; } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java index 62223c08d..2f28f8d9c 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatConversationPanel.java @@ -11,6 +11,7 @@ import java.awt.event.*; import java.io.*; import java.net.*; +import java.text.*; import java.util.*; import java.util.regex.*; @@ -29,6 +30,7 @@ import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.desktoputil.SwingWorker; import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.history.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.replacement.*; import net.java.sip.communicator.service.replacement.smilies.*; @@ -136,12 +138,12 @@ public class ChatConversationPanel /** * The timestamp of the last incoming message. */ - private long lastIncomingMsgTimestamp; + private Date lastIncomingMsgTimestamp = new Date(0); /** * The timestamp of the last message. */ - private long lastMessageTimestamp; + private Date lastMessageTimestamp = new Date(0); /** * Indicates if this component is rendering a history conversation. @@ -415,7 +417,7 @@ public String processMessage( ChatMessage chatMessage, = contactDisplayName.replaceAll("'", "'"); } - long date = chatMessage.getDate(); + Date date = chatMessage.getDate(); String messageType = chatMessage.getMessageType(); String messageTitle = chatMessage.getMessageTitle(); String message = chatMessage.getMessage(); @@ -435,7 +437,7 @@ public String processMessage( ChatMessage chatMessage, if (messageType.equals(Chat.INCOMING_MESSAGE)) { - this.lastIncomingMsgTimestamp = System.currentTimeMillis(); + this.lastIncomingMsgTimestamp = new Date(); chatString = ChatHtmlUtils.createIncomingMessageTag( lastMessageUID, @@ -1227,7 +1229,7 @@ public JTextPane getChatTextPane() * * @return The time of the last received message. */ - public long getLastIncomingMsgTimestamp() + public Date getLastIncomingMsgTimestamp() { return lastIncomingMsgTimestamp; } @@ -1428,7 +1430,15 @@ public Date getPageFirstMsgTimestamp() .getAttributes().getAttribute(ChatHtmlUtils.DATE_ATTRIBUTE) .toString(); - return new Date(Long.parseLong(dateObject)); + SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); + try + { + return sdf.parse(dateObject); + } + catch (ParseException e) + { + return new Date(0); + } } /** @@ -1438,7 +1448,7 @@ public Date getPageFirstMsgTimestamp() */ public Date getPageLastMsgTimestamp() { - long timestamp = 0; + Date timestamp = new Date(0); if (lastMessageUID != null) { @@ -1452,12 +1462,21 @@ public Date getPageLastMsgTimestamp() = lastMsgElement.getAttributes().getAttribute( ChatHtmlUtils.DATE_ATTRIBUTE); + SimpleDateFormat sdf + = new SimpleDateFormat(HistoryService.DATE_FORMAT); if (date != null) - timestamp = Long.parseLong(date.toString()); + { + try + { + timestamp = sdf.parse(date.toString()); + } + catch (ParseException e) + {} + } } } - return new Date(timestamp); + return timestamp; } /** @@ -1596,8 +1615,10 @@ public void addComponent(ChatConversationComponent component) style.addAttribute(StyleConstants.ComponentAttribute, wrapPanel); style.addAttribute(Attribute.ID, ChatHtmlUtils.MESSAGE_TEXT_ID); + SimpleDateFormat sdf + = new SimpleDateFormat(HistoryService.DATE_FORMAT); style.addAttribute(ChatHtmlUtils.DATE_ATTRIBUTE, - component.getDate().getTime()); + sdf.format(component.getDate())); scrollToBottomIsPending = true; @@ -1819,7 +1840,8 @@ private boolean isConsecutiveMessage(ChatMessage chatMessage) .equals(Chat.HISTORY_OUTGOING_MESSAGE)) && contactAddress.equals(chatMessage.getContactName()) // And if the new message is within a minute from the last one. - && ((chatMessage.getDate() - lastMessageTimestamp) + && ((chatMessage.getDate().getTime() + - lastMessageTimestamp.getTime()) < 60000)) { lastMessageTimestamp = chatMessage.getDate(); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java index 27d67f839..dc9ff348a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatHtmlUtils.java @@ -5,9 +5,13 @@ */ package net.java.sip.communicator.impl.gui.main.chat; +import java.text.*; +import java.util.*; + import javax.swing.text.html.HTML.Tag; import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.service.history.*; import net.java.sip.communicator.util.*; /** @@ -83,7 +87,7 @@ public static String createIncomingMessageTag( String contactName, String contactDisplayName, String avatarPath, - long date, + Date date, String message, String contentType, boolean isHistory, @@ -129,7 +133,7 @@ public static String createOutgoingMessageTag( String messageID, String contactName, String contactDisplayName, String avatarPath, - long date, + Date date, String message, String contentType, boolean isHistory, @@ -173,7 +177,7 @@ public static String createMessageTag( String messageID, String contactName, String message, String contentType, - long date, + Date date, boolean isEdited, boolean isHistory, boolean isSimpleTheme) @@ -215,15 +219,18 @@ private static String createSimpleIncomingMessageTag( String contactName, String contactDisplayName, String avatarPath, - long date, + Date date, String message, String contentType, boolean isHistory) { StringBuffer headerBuffer = new StringBuffer(); + + SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); headerBuffer.append("