This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 97b07d849b56a10fe6fd8082bcde8217b102ff81
Author: Chenjp <ch...@msn.com>
AuthorDate: Thu Sep 12 08:37:21 2024 +0800

    enhance performance and modify test case name
---
 java/org/apache/tomcat/util/http/FastHttpDateFormat.java            | 4 +++-
 .../{TesterFastHttpDateFormat.java => TestFastHttpDateFormat.java}  | 6 +-----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java 
b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
index 49830e3dcc..1b83d6e4e7 100644
--- a/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
+++ b/java/org/apache/tomcat/util/http/FastHttpDateFormat.java
@@ -104,8 +104,10 @@ public final class FastHttpDateFormat {
      */
     public static String getCurrentDate() {
         long now = System.currentTimeMillis();
+        // Ignore millisecond part.
+        now -= now % 1000L;
         // Handle case where time moves backwards (e.g. system time corrected)
-        if (now - now%1000L != currentDateGenerated - 
currentDateGenerated%1000L) {
+        if (now != currentDateGenerated) {
             currentDate = FORMAT_RFC5322.format(new Date(now));
             currentDateGenerated = now;
         }
diff --git a/test/org/apache/tomcat/util/http/TesterFastHttpDateFormat.java 
b/test/org/apache/tomcat/util/http/TestFastHttpDateFormat.java
similarity index 80%
rename from test/org/apache/tomcat/util/http/TesterFastHttpDateFormat.java
rename to test/org/apache/tomcat/util/http/TestFastHttpDateFormat.java
index f9b17415ae..0c915669f9 100644
--- a/test/org/apache/tomcat/util/http/TesterFastHttpDateFormat.java
+++ b/test/org/apache/tomcat/util/http/TestFastHttpDateFormat.java
@@ -3,7 +3,7 @@ package org.apache.tomcat.util.http;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class TesterFastHttpDateFormat {
+public class TestFastHttpDateFormat {
     @Test
     public void testGetCurrentDateInSameSecond() {
         long now = System.currentTimeMillis();
@@ -13,14 +13,12 @@ public class TesterFastHttpDateFormat {
         }
         now = System.currentTimeMillis();
         String s1 = FastHttpDateFormat.getCurrentDate();
-        System.out.println("1st:" + System.currentTimeMillis() + ", " + s1);
         long lastMillisInSameSecond = now - now % 1000 + 900L;
         try {
             Thread.sleep(lastMillisInSameSecond - now);
         } catch (InterruptedException e) {
         }
         String s2 = FastHttpDateFormat.getCurrentDate();
-        System.out.println("2nd:" + System.currentTimeMillis() + ", " + s2);
         Assert.assertEquals("Two same RFC5322 format dates are expected.", s1, 
s2);
     }
 
@@ -34,7 +32,6 @@ public class TesterFastHttpDateFormat {
         }
         now = System.currentTimeMillis();
         String s1 = FastHttpDateFormat.getCurrentDate();
-        System.out.println("1st:" + System.currentTimeMillis() + ", " + s1);
         long firstMillisOfNextSecond = now - now % 1000 + 1100L;
         try {
             Thread.sleep(firstMillisOfNextSecond - now);
@@ -42,7 +39,6 @@ public class TesterFastHttpDateFormat {
         }
 
         String s2 = FastHttpDateFormat.getCurrentDate();
-        System.out.println("2nd:" + System.currentTimeMillis() + ", " + s2);
         Assert.assertFalse("Two different RFC5322 format dates are expected.", 
s1.equals(s2));
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to