[logback-dev] svn commit: r969 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/rolling/helper main/java/ch/qos/logback/core/util test/java/ch/qos/logback/core/rolling test/java/ch/qos/logback/core/util
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Mon Nov 20 22:57:07 CET 2006
Author: ceki
Date: Mon Nov 20 22:57:06 2006
New Revision: 969
Added:
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
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compress.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java
Log:
- Added TimeUtil with accompanying TC
- Other Minor changes
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compress.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compress.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/rolling/helper/Compress.java Mon Nov 20 22:57:06 2006
@@ -163,4 +163,9 @@
+ nameOfFile2gz + "] into [" + nameOfgzedFile + "].", this, e));
}
}
+
+ @Override
+ public String toString() {
+ return "c.q.l.core.rolling.helper.Compress";
+ }
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/TimeUtil.java Mon Nov 20 22:57:06 2006
@@ -0,0 +1,43 @@
+package ch.qos.logback.core.util;
+
+import java.util.Calendar;
+import java.util.Date;
+
+public class TimeUtil {
+
+ static long computeStartOfNextDay(long now) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date(now));
+
+ cal.add(Calendar.DAY_OF_MONTH, 1);
+ cal.set(Calendar.MILLISECOND, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ return cal.getTime().getTime();
+ }
+
+ static long computeStartOfNextWeek(long now) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(new Date(now));
+
+ cal.add(Calendar.DAY_OF_MONTH, getFirstDayOfWeek());
+
+
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+
+ return cal.getTime().getTime();
+ }
+
+// this.set(Calendar.DAY_OF_WEEK, getFirstDayOfWeek());
+// this.set(Calendar.HOUR_OF_DAY, 0);
+// this.set(Calendar.MINUTE, 0);
+// this.set(Calendar.SECOND, 0);
+// this.set(Calendar.MILLISECOND, 0);
+// this.add(Calendar.WEEK_OF_YEAR, 1);
+
+
+}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/DelayerUtil.java Mon Nov 20 22:57:06 2006
@@ -47,5 +47,4 @@
} catch (Exception e) {
}
}
-
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/PackageTest.java Mon Nov 20 22:57:06 2006
@@ -21,6 +21,7 @@
suite.addTestSuite(DurationTest.class);
suite.addTestSuite(FileSizeTest.class);
suite.addTestSuite(PropertySetterTest.class);
+ suite.addTestSuite(TimeUtilTest.class);
return suite;
}
}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/TimeUtilTest.java Mon Nov 20 22:57:06 2006
@@ -0,0 +1,29 @@
+package ch.qos.logback.core.util;
+
+import junit.framework.TestCase;
+
+public class TimeUtilTest extends TestCase {
+
+ public TimeUtilTest(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+ public void testDay() {
+ // Mon Nov 20 18:05:17 CET 2006
+ long now = 1164042317522L;
+ // Tue Nov 21 00:00:00 CET 2006
+ long expected = 1164063600000L;
+ long computed = TimeUtil.computeStartOfNextDay(now);
+ assertEquals(expected - now, 1000*(3600*5+60*54+42)+478);
+ assertEquals(expected, computed);
+ }
+}
More information about the logback-dev
mailing list