[logback-dev] svn commit: r989 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/util test/java/ch/qos/logback/core/util

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Nov 22 21:54:14 CET 2006


Author: ceki
Date: Wed Nov 22 21:54:13 2006
New Revision: 989

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java
   logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java

Log:
added support by minute and by hour computations

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java	Wed Nov 22 21:54:13 2006
@@ -13,6 +13,25 @@
     cal.add(Calendar.SECOND, 1);
     return cal.getTime().getTime();
   }
+
+  public static long computeStartOfNextMinute(long now) {
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+    cal.set(Calendar.MILLISECOND, 0);
+    cal.set(Calendar.SECOND, 0);
+    cal.add(Calendar.MINUTE, 1);
+    return cal.getTime().getTime();
+  }
+
+  public static long computeStartOfNextHour(long now) {
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+    cal.set(Calendar.MILLISECOND, 0);
+    cal.set(Calendar.SECOND, 0);
+    cal.set(Calendar.MINUTE, 0);
+    cal.add(Calendar.HOUR, 1);
+    return cal.getTime().getTime();
+  }
   
   public static long computeStartOfNextDay(long now) {
     Calendar cal = Calendar.getInstance();

Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java	(original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java	Wed Nov 22 21:54:13 2006
@@ -22,13 +22,34 @@
   public void testSecond() {
     // Mon Nov 20 18:05:17,522 CET 2006
     long now = 1164042317522L;
-    // Mon Nov 20 18:06:00,000 CET 2006
+    //Mon Nov 20 18:05:18,000 CET 2006
     long expected = 1164042318000L;
     long computed = TimeUtil.computeStartOfNextSecond(now);
     assertEquals(expected - now, 478); 
     assertEquals(expected, computed);
   }
   
+  public void testMinute() {
+    // Mon Nov 20 18:05:17,522 CET 2006
+    long now = 1164042317522L;
+    // Mon Nov 20 18:06:00 CET 2006
+    long expected = 1164042360000L;
+    long computed = TimeUtil.computeStartOfNextMinute(now);
+    assertEquals(expected - now, 1000*42+478); 
+    assertEquals(expected, computed);
+  }
+
+  public void testHour() {
+    // Mon Nov 20 18:05:17,522 CET 2006
+    long now = 1164042317522L;
+    // Mon Nov 20 19:00:00 CET 2006
+    long expected = 1164045600000L;
+    System.out.println(new Date(expected));
+    long computed = TimeUtil.computeStartOfNextHour(now);
+    assertEquals(expected - now, 1000*(42+60*54)+478); 
+    assertEquals(expected, computed);
+  }
+  
   public void testDay() {
     // Mon Nov 20 18:05:17 CET 2006
     long now = 1164042317522L;



More information about the logback-dev mailing list