[logback-dev] svn commit: r973 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran/action main/java/ch/qos/logback/core/joran/spi 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 12:07:24 CET 2006


Author: ceki
Date: Tue Nov 21 12:07:23 2006
New Revision: 973

Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
   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:
- fixed problem with TimeUtilTest when run European contries where the first day
  of the week is Monday instead of Sunday.
- Renamed InterpretationContext.addProperty as addSubstitutionProperty
- Fixed bug in PropertyAction

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/PropertyAction.java	Tue Nov 21 12:07:23 2006
@@ -43,7 +43,7 @@
   public void begin(
     InterpretationContext ec, String localName, Attributes attributes) {
     String name = attributes.getValue(NAME_ATTRIBUTE);
-    String value = attributes.getValue(NAME_ATTRIBUTE);
+    String value = attributes.getValue(VALUE_ATTRIBUTE);
     String fileName = attributes.getValue(FILE_ATTRIBUTE);
 
     if (

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/SubstitutionPropertyAction.java	Tue Nov 21 12:07:23 2006
@@ -32,7 +32,7 @@
   }
   
   public void setProperty(InterpretationContext ec, String key, String value) {
-    ec.addProperty(key, value);
+    ec.addSubstitutionProperty(key, value);
     //ec.getContext().setProperty(key, value);
   }
 }

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java	Tue Nov 21 12:07:23 2006
@@ -99,7 +99,7 @@
    * Add a property to the properties of this execution context. If the property
    * exists already, it is overwritten.
    */
-  public void addProperty(String key, String value) {
+  public void addSubstitutionProperty(String key, String value) {
     if (key == null || value == null) {
       return;
     }
@@ -121,7 +121,7 @@
     Iterator i = props.keySet().iterator();
     while (i.hasNext()) {
       String key = (String) i.next();
-      addProperty(key, props.getProperty(key));
+      addSubstitutionProperty(key, props.getProperty(key));
     }
   }
 

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 12:07:23 2006
@@ -20,14 +20,13 @@
   static long computeStartOfNextWeek(long now) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date(now));
-
+    
     cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
     cal.set(Calendar.HOUR_OF_DAY, 0);
     cal.set(Calendar.MINUTE, 0);
     cal.set(Calendar.SECOND, 0);
     cal.set(Calendar.MILLISECOND, 0);
     cal.add(Calendar.WEEK_OF_YEAR, 1);
-    
     return cal.getTime().getTime();
   }
 

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 12:07:23 2006
@@ -1,5 +1,6 @@
 package ch.qos.logback.core.util;
 
+import java.util.Calendar;
 import java.util.Date;
 
 import junit.framework.TestCase;
@@ -33,9 +34,22 @@
     // Mon Nov 20 18:05:17 CET 2006
     long now = 1164042317522L;
     // Sun Nov 26 00:00:00 CET 2006
+    
     long expected = 1164495600000L;
+    
+    Calendar cal = Calendar.getInstance();
+    cal.setTime(new Date(now));
+    
+    int dayOffset = cal.getFirstDayOfWeek()-Calendar.SUNDAY;
+    if(dayOffset != 0) {
+      expected += 24L*3600*1000* (cal.getFirstDayOfWeek()-Calendar.SUNDAY);
+    }
+    
     long computed = TimeUtil.computeStartOfNextWeek(now);
-    assertEquals(expected - now, 1000*(3600*(5+24*5)+60*54+42)+478); 
+//    System.out.println("now      "+new Date(now));
+//    System.out.println("computed "+new Date(computed));
+//    System.out.println("expected "+new Date(expected));
+    assertEquals(expected - now, 1000*(3600*(5+24*(5+dayOffset))+60*54+42)+478); 
     assertEquals(expected, computed);
   }
   
@@ -45,9 +59,6 @@
     // Fri Dec 01 00:00:00 CET 2006
     long expected = 1164927600000L;
     long computed = TimeUtil.computeStartOfNextMonth(now);
-    
-    System.out.println(computed);
-    System.out.println(new Date(computed));
     assertEquals(expected - now, 1000*(3600*(5+24*10)+60*54+42)+478); 
     assertEquals(expected, computed);
   }



More information about the logback-dev mailing list