tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 20380] New: - AccessLogValve incorrectly calculates timezone
Date Sat, 31 May 2003 05:15:51 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20380>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20380

AccessLogValve incorrectly calculates timezone

           Summary: AccessLogValve incorrectly calculates timezone
           Product: Tomcat 4
           Version: 4.1.24
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Catalina
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: jon@eaves.org


AccessLogValve.java assumes that all timezones are exact multiples of an hour.
This doesn't work when you live in Adelaide (Australia) and other places around
the world.

When configured in that timezone, the log message looks like:

127.0.0.1 - - [31/May/2003:14:26:23 9050] "GET /hello HTTP/1.1" 404 683

(Notice the 9050!)

I found this when I was working on a MonthlyAccessLogValve, and fixed it there.
This will presumably be the same in other parts of the logging functionality.

Here's some code that appears to correctly calculate the timezone for both
hour based, and half-hour based timezones.

    /**
     * Creating a time zone that is formatted as "+|-HHMM" is not
     * made easy by the Java classes. This provides a means of
     * creating a suitable formatted timezone.
     */
    private String createTimeZoneFormat(TimeZone tz, Date now)
    {
        int raw = (tz.getRawOffset() / 60000);
        if (tz.inDaylightTime(now))
        {
            raw += 60;
        }
        int hours = raw / 60;
        int mins = raw - (hours*60);

        StringBuffer sb = new StringBuffer();

        if (hours >=0)
        {
            sb.append('+');
        }
        else
        {
            sb.append('-');
            hours *= (-1);
            mins *= (-1);
        }
        
        if (hours < 10)
        {
            sb.append('0');
        }
        sb.append(hours);
        
        if (mins < 10)
        {
            sb.append('0');
        }
        sb.append(mins);
        
        return sb.toString();
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message