[sip-comm-dev] Re: svn commit: r5530 - trunk/src/net/java/sip/communicator: impl/gui/main/chat/history util


#1

Hello Yana,

I may be misinterpreting here so please forgive me if that's the case,
I just thought I'd mention it in case it's a problem. I'm having some
doubts about GuiUtils.compareDatesOnly because it says it determines
whether a data is before/after/equal to another date (in terms of the
day of month, month and year) but then it requests:

if((day1 < day2)
                && (month1 <= month2)
                && (year1 <= year2))
        {
            return -1;
        }

Wouldn't the above say that 31.12.2008 is after 01.01.2009?

I guess one shouldn't care about the day of month and the month if the
years are different. And if the years are equal, the day of month is
irrelevant if the months are different.

Best regards,
Lubo

···

On Thu, Jul 16, 2009 at 5:49 PM, <yanas@dev.java.net> wrote:

Author: yanas
Date: 2009-07-16 14:49:53+0000
New Revision: 5530

Modified:
trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java
trunk/src/net/java/sip/communicator/util/GuiUtils.java

Log:
Fix chat history duplicate dates on incoming message.

Modified: trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java?view=diff&rev=5530&p1=trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java&p2=trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java&r1=5529&r2=5530

--- trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java 2009-07-16 14:49:53+0000
@@ -733,7 +733,7 @@
public void messageReceived(MessageReceivedEvent evt)
{
Contact sourceContact = evt.getSourceContact();
-
+
this.processMessage(sourceContact, evt.getTimestamp(),
Constants.INCOMING_MESSAGE,
evt.getSourceMessage().getContent(),
@@ -789,7 +789,8 @@
Date lastDate = datesPanel.getDate(lastDateIndex);

        if\(lastDate \!= null

- && GuiUtils.compareDates(lastDate.getTime(), timestamp) == 0)
+ && GuiUtils.compareDatesOnly(
+ lastDate.getTime(), timestamp) == 0)
{
HTMLDocument document = dateHistoryTable.get(lastDate);

@@ -797,7 +798,8 @@
{
ChatMessage chatMessage = new ChatMessage(
contact.getDisplayName(),
- timestamp, messageType,
+ timestamp,
+ messageType,
messageContent,
messageContentType);

@@ -808,7 +810,7 @@
}
}
else if (lastDate == null
- || GuiUtils.compareDates(lastDate.getTime(), timestamp) < 0)
+ || GuiUtils.compareDatesOnly(lastDate.getTime(), timestamp) < 0)
{
long milisecondsPerDay = 24*60*60*1000;

Modified: trunk/src/net/java/sip/communicator/util/GuiUtils.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/util/GuiUtils.java?view=diff&rev=5530&p1=trunk/src/net/java/sip/communicator/util/GuiUtils.java&p2=trunk/src/net/java/sip/communicator/util/GuiUtils.java&r1=5529&r2=5530

--- trunk/src/net/java/sip/communicator/util/GuiUtils.java (original)
+++ trunk/src/net/java/sip/communicator/util/GuiUtils.java 2009-07-16 14:49:53+0000
@@ -22,6 +22,8 @@
{
private static Calendar c1 = Calendar.getInstance();

+ private static Calendar c2 = Calendar.getInstance();
+
/**
* Number of milliseconds in a second.
*/
@@ -97,6 +99,48 @@
}

/\*\*

+ * Compares the two dates. The comparison is based only on the day, month
+ * and year values. Returns 0 if the two dates are equals, a value < 0 if
+ * the first date is before the second one and > 0 if the first date is
+ * after the second one.
+ * @param date1 the first date to compare
+ * @param date2 the second date to compare with
+ * @return Returns 0 if the two dates are equals, a value < 0 if
+ * the first date is before the second one and > 0 if the first date is
+ * after the second one
+ */
+ public static int compareDatesOnly(long date1, long date2)
+ {
+ c1.setTimeInMillis(date1);
+ c2.setTimeInMillis(date2);
+
+ int day1 = c1.get(Calendar.DAY_OF_MONTH);
+ int month1 = c1.get(Calendar.MONTH);
+ int year1 = c1.get(Calendar.YEAR);
+
+ int day2 = c2.get(Calendar.DAY_OF_MONTH);
+ int month2 = c2.get(Calendar.MONTH);
+ int year2 = c2.get(Calendar.YEAR);
+
+ if((day1 == day2)
+ && (month1 == month2)
+ && (year1 == year2))
+ {
+ return 0;
+ }
+ else if((day1 < day2)
+ && (month1 <= month2)
+ && (year1 <= year2))
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ /**
* Formats the given date. The result format is the following:
* [Month] [Day], [Year]. For example: Dec 24, 2000.
* @param date the date to format
@@ -173,12 +217,12 @@
int sec
= (int)(( difMil - days*milPerDay - hour*milPerHour - min*milPerMin)
/ milPerSec);
-
+
c1.clear();
c1.set(Calendar.HOUR, hour);
c1.set(Calendar.MINUTE, min);
c1.set(Calendar.SECOND, sec);
-
+
return c1.getTime();
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net


#2

Hi Lubo,

Thanks for noticing!:slight_smile: I have just returned an old method and didn't noticed that there was a bug. It should be ok now.

Cheers,
Yana

Lubomir Marinov wrote:

···

Hello Yana,

I may be misinterpreting here so please forgive me if that's the case,
I just thought I'd mention it in case it's a problem. I'm having some
doubts about GuiUtils.compareDatesOnly because it says it determines
whether a data is before/after/equal to another date (in terms of the
day of month, month and year) but then it requests:

if((day1 < day2)
                && (month1 <= month2)
                && (year1 <= year2))
        {
            return -1;
        }

Wouldn't the above say that 31.12.2008 is after 01.01.2009?

I guess one shouldn't care about the day of month and the month if the
years are different. And if the years are equal, the day of month is
irrelevant if the months are different.

Best regards,
Lubo

On Thu, Jul 16, 2009 at 5:49 PM, <yanas@dev.java.net> wrote:

Author: yanas
Date: 2009-07-16 14:49:53+0000
New Revision: 5530

Modified:
  trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java
  trunk/src/net/java/sip/communicator/util/GuiUtils.java

Log:
Fix chat history duplicate dates on incoming message.

Modified: trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java?view=diff&rev=5530&p1=trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java&p2=trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java&r1=5529&r2=5530

--- trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java (original)
+++ trunk/src/net/java/sip/communicator/impl/gui/main/chat/history/HistoryWindow.java 2009-07-16 14:49:53+0000
@@ -733,7 +733,7 @@
    public void messageReceived(MessageReceivedEvent evt)
    {
        Contact sourceContact = evt.getSourceContact();
-
+
        this.processMessage(sourceContact, evt.getTimestamp(),
            Constants.INCOMING_MESSAGE,
            evt.getSourceMessage().getContent(),
@@ -789,7 +789,8 @@
            Date lastDate = datesPanel.getDate(lastDateIndex);

            if(lastDate != null
- && GuiUtils.compareDates(lastDate.getTime(), timestamp) == 0)
+ && GuiUtils.compareDatesOnly(
+ lastDate.getTime(), timestamp) == 0)
            {
                HTMLDocument document = dateHistoryTable.get(lastDate);

@@ -797,7 +798,8 @@
                {
                    ChatMessage chatMessage = new ChatMessage(
                        contact.getDisplayName(),
- timestamp, messageType,
+ timestamp,
+ messageType,
                        messageContent,
                        messageContentType);

@@ -808,7 +810,7 @@
                }
            }
            else if (lastDate == null
- || GuiUtils.compareDates(lastDate.getTime(), timestamp) < 0)
+ || GuiUtils.compareDatesOnly(lastDate.getTime(), timestamp) < 0)
            {
                long milisecondsPerDay = 24*60*60*1000;

Modified: trunk/src/net/java/sip/communicator/util/GuiUtils.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/util/GuiUtils.java?view=diff&rev=5530&p1=trunk/src/net/java/sip/communicator/util/GuiUtils.java&p2=trunk/src/net/java/sip/communicator/util/GuiUtils.java&r1=5529&r2=5530

--- trunk/src/net/java/sip/communicator/util/GuiUtils.java (original)
+++ trunk/src/net/java/sip/communicator/util/GuiUtils.java 2009-07-16 14:49:53+0000
@@ -22,6 +22,8 @@
{
    private static Calendar c1 = Calendar.getInstance();

+ private static Calendar c2 = Calendar.getInstance();
+
    /**
     * Number of milliseconds in a second.
     */
@@ -97,6 +99,48 @@
    }

    /**
+ * Compares the two dates. The comparison is based only on the day, month
+ * and year values. Returns 0 if the two dates are equals, a value < 0 if
+ * the first date is before the second one and > 0 if the first date is
+ * after the second one.
+ * @param date1 the first date to compare
+ * @param date2 the second date to compare with
+ * @return Returns 0 if the two dates are equals, a value < 0 if
+ * the first date is before the second one and > 0 if the first date is
+ * after the second one
+ */
+ public static int compareDatesOnly(long date1, long date2)
+ {
+ c1.setTimeInMillis(date1);
+ c2.setTimeInMillis(date2);
+
+ int day1 = c1.get(Calendar.DAY_OF_MONTH);
+ int month1 = c1.get(Calendar.MONTH);
+ int year1 = c1.get(Calendar.YEAR);
+
+ int day2 = c2.get(Calendar.DAY_OF_MONTH);
+ int month2 = c2.get(Calendar.MONTH);
+ int year2 = c2.get(Calendar.YEAR);
+
+ if((day1 == day2)
+ && (month1 == month2)
+ && (year1 == year2))
+ {
+ return 0;
+ }
+ else if((day1 < day2)
+ && (month1 <= month2)
+ && (year1 <= year2))
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+
+ /**
     * Formats the given date. The result format is the following:
     * [Month] [Day], [Year]. For example: Dec 24, 2000.
     * @param date the date to format
@@ -173,12 +217,12 @@
        int sec
            = (int)(( difMil - days*milPerDay - hour*milPerHour - min*milPerMin)
                    / milPerSec);
-
+
        c1.clear();
        c1.set(Calendar.HOUR, hour);
        c1.set(Calendar.MINUTE, min);
        c1.set(Calendar.SECOND, sec);
-
+
        return c1.getTime();
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net