[logback-dev] svn commit: r978 - 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
Tue Nov 21 21:50:11 CET 2006


Author: ceki
Date: Tue Nov 21 21:50:11 2006
New Revision: 978

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 for computing seconds

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	Tue Nov 21 21:50:11 2006
@@ -5,7 +5,16 @@
 
 public class TimeUtil {
 
-  static long computeStartOfNextDay(long now) {
+  
+  public static long computeStartOfNextSecond(long now) {
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+    cal.set(Calendar.MILLISECOND, 0);
+    cal.add(Calendar.SECOND, 1);
+    return cal.getTime().getTime();
+  }
+  
+  public static long computeStartOfNextDay(long now) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(now));
 
@@ -17,7 +26,7 @@
     return cal.getTime().getTime();
   }
   
-  static long computeStartOfNextWeek(long now) {
+  public static long computeStartOfNextWeek(long now) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(now));
     
@@ -30,7 +39,7 @@
     return cal.getTime().getTime();
   }
 
-  static long computeStartOfNextMonth(long now) {
+  public static long computeStartOfNextMonth(long now) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(now));
 

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	Tue Nov 21 21:50:11 2006
@@ -19,6 +19,15 @@
     super.tearDown();
   }
 
+  public void testSecond() {
+    // Mon Nov 20 18:05:17,522 CET 2006
+    long now = 1164042317522L;
+    // Mon Nov 20 18:06:00,000 CET 2006
+    long expected = 1164042318000L;
+    long computed = TimeUtil.computeStartOfNextSecond(now);
+    assertEquals(expected - now, 478); 
+    assertEquals(expected, computed);
+  }
   
   public void testDay() {
     // Mon Nov 20 18:05:17 CET 2006



More information about the logback-dev mailing list