markt 2005/03/28 10:53:19 Modified: catalina/src/share/org/apache/catalina/valves AccessLogValve.java Log: Fix bug 20380. Timezone reported in access log should include any adjustment necesary for Daylight Saving Time. Revision Changes Path 1.20 +39 -17 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java Index: AccessLogValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- AccessLogValve.java 27 Mar 2005 20:18:01 -0000 1.19 +++ AccessLogValve.java 28 Mar 2005 18:53:19 -0000 1.20 @@ -25,6 +25,7 @@ import java.net.InetAddress; import java.text.SimpleDateFormat; import java.text.DecimalFormat; +import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import javax.servlet.ServletException; @@ -265,12 +266,22 @@ */ private SimpleDateFormat timeFormatter = null; - /** - * The time zone relative to GMT. + * The system timezone. + */ + private TimeZone timezone = null; + + /** + * The time zone offset relative to GMT in text form when daylight saving + * is not in operation. */ - private String timeZone = null; + private String timeZoneNoDST = null; + /** + * The time zone offset relative to GMT in text form when daylight saving + * is in operation. + */ + private String timeZoneDST = null; /** * The system time when we last updated the Date that this valve @@ -570,15 +581,15 @@ } result.append("["); - result.append(dayFormatter.format(date)); // Day + result.append(dayFormatter.format(date)); // Day result.append('/'); result.append(lookup(monthFormatter.format(date))); // Month result.append('/'); - result.append(yearFormatter.format(date)); // Year + result.append(yearFormatter.format(date)); // Year result.append(':'); - result.append(timeFormatter.format(date)); // Time + result.append(timeFormatter.format(date)); // Time result.append(space); - result.append(timeZone); // Time Zone + result.append(getTimeZone(date)); // Time Zone result.append("] \""); result.append(hreq.getMethod()); @@ -880,7 +891,7 @@ temp.append(':'); temp.append(timeFormatter.format(date)); // Time temp.append(' '); - temp.append(timeZone); // Timezone + temp.append(getTimeZone(date)); // Timezone temp.append(']'); value = temp.toString(); } else if (pattern == 'T') { @@ -999,7 +1010,15 @@ } - + private String getTimeZone(Date date) { + if (timezone.inDaylightTime(date)) { + return timeZoneDST; + } else { + return timeZoneNoDST; + } + } + + private String calculateTimeZoneOffset(long offset) { StringBuffer tz = new StringBuffer(); if ((offset<0)) { @@ -1080,21 +1099,24 @@ started = true; // Initialize the timeZone, Date formatters, and currentDate - TimeZone tz = TimeZone.getDefault(); - timeZone = calculateTimeZoneOffset(tz.getRawOffset()); + timezone = TimeZone.getDefault(); + timeZoneNoDST = calculateTimeZoneOffset(timezone.getRawOffset()); + Calendar calendar = Calendar.getInstance(timezone); + int offset = calendar.get(Calendar.DST_OFFSET); + timeZoneDST = calculateTimeZoneOffset(timezone.getRawOffset()+offset); if (fileDateFormat==null || fileDateFormat.length()==0) fileDateFormat = "yyyy-MM-dd"; dateFormatter = new SimpleDateFormat(fileDateFormat); - dateFormatter.setTimeZone(tz); + dateFormatter.setTimeZone(timezone); dayFormatter = new SimpleDateFormat("dd"); - dayFormatter.setTimeZone(tz); + dayFormatter.setTimeZone(timezone); monthFormatter = new SimpleDateFormat("MM"); - monthFormatter.setTimeZone(tz); + monthFormatter.setTimeZone(timezone); yearFormatter = new SimpleDateFormat("yyyy"); - yearFormatter.setTimeZone(tz); + yearFormatter.setTimeZone(timezone); timeFormatter = new SimpleDateFormat("HH:mm:ss"); - timeFormatter.setTimeZone(tz); + timeFormatter.setTimeZone(timezone); currentDate = new Date(); dateStamp = dateFormatter.format(currentDate); timeTakenFormatter = new DecimalFormat("0.000");
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]