ASF Bugzilla – Attachment 23789 Details for
Bug 47350
ISO8601DateFormat and AbsoluteTimeDateFormat don't support mulitple timezone
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Unit test + fix
bug47350.patch (text/plain), 6.94 KB, created by
Gilles Scokart
on 2009-06-10 13:36:43 UTC
(
hide
)
Description:
Unit test + fix
Filename:
MIME Type:
Creator:
Gilles Scokart
Created:
2009-06-10 13:36:43 UTC
Size:
6.94 KB
patch
obsolete
>Index: tests/src/java/org/apache/log4j/helpers/ISO8601DateFormatTest.java >=================================================================== >--- tests/src/java/org/apache/log4j/helpers/ISO8601DateFormatTest.java (revision 0) >+++ tests/src/java/org/apache/log4j/helpers/ISO8601DateFormatTest.java (revision 0) >@@ -0,0 +1,50 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+ >+// >+// Log4j uses the JUnit framework for internal unit testing. JUnit >+// available from >+// >+// http://www.junit.org >+ >+ >+package org.apache.log4j.helpers; >+ >+import java.util.Date; >+import java.util.TimeZone; >+ >+import junit.framework.TestCase; >+ >+public class ISO8601DateFormatTest extends TestCase { >+ >+ public void testDateFormatingUsingDifferentTimeZone() { >+ ISO8601DateFormat f1 = new ISO8601DateFormat(); >+ ISO8601DateFormat f2 = new ISO8601DateFormat(); >+ f1.setTimeZone(TimeZone.getTimeZone("GMT")); >+ f2.setTimeZone(TimeZone.getTimeZone("GMT+1:00")); >+ Date date = new Date(900000); >+ >+ StringBuffer sbuf = new StringBuffer(); >+ f1.format(date, sbuf, null); >+ assertEquals("1970-01-01 00:15:00,000", sbuf.toString()); >+ >+ sbuf = new StringBuffer(); >+ f2.format(date, sbuf, null); >+ assertEquals("1970-01-01 01:15:00,000", sbuf.toString()); >+ >+ } >+} > >Property changes on: tests/src/java/org/apache/log4j/helpers/ISO8601DateFormatTest.java >___________________________________________________________________ >Added: svn:keywords > + Author Date Id Revision >Added: svn:eol-style > + native > >Index: tests/src/java/org/apache/log4j/helpers/AbsoluteTimeDateFormatTest.java >=================================================================== >--- tests/src/java/org/apache/log4j/helpers/AbsoluteTimeDateFormatTest.java (revision 0) >+++ tests/src/java/org/apache/log4j/helpers/AbsoluteTimeDateFormatTest.java (revision 0) >@@ -0,0 +1,50 @@ >+/* >+ * Licensed to the Apache Software Foundation (ASF) under one or more >+ * contributor license agreements. See the NOTICE file distributed with >+ * this work for additional information regarding copyright ownership. >+ * The ASF licenses this file to You under the Apache License, Version 2.0 >+ * (the "License"); you may not use this file except in compliance with >+ * the License. You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ */ >+ >+// >+// Log4j uses the JUnit framework for internal unit testing. JUnit >+// available from >+// >+// http://www.junit.org >+ >+ >+package org.apache.log4j.helpers; >+ >+import java.util.Date; >+import java.util.TimeZone; >+ >+import junit.framework.TestCase; >+ >+public class AbsoluteTimeDateFormatTest extends TestCase { >+ >+ public void testDateFormatingUsingDifferentTimeZone() { >+ AbsoluteTimeDateFormat f1 = new AbsoluteTimeDateFormat(); >+ AbsoluteTimeDateFormat f2 = new AbsoluteTimeDateFormat(); >+ f1.setTimeZone(TimeZone.getTimeZone("GMT")); >+ f2.setTimeZone(TimeZone.getTimeZone("GMT+1:00")); >+ Date date = new Date(900000); >+ >+ StringBuffer sbuf = new StringBuffer(); >+ f1.format(date, sbuf, null); >+ assertEquals("00:15:00,000", sbuf.toString()); >+ >+ sbuf = new StringBuffer(); >+ f2.format(date, sbuf, null); >+ assertEquals("01:15:00,000", sbuf.toString()); >+ >+ } >+} > >Property changes on: tests/src/java/org/apache/log4j/helpers/AbsoluteTimeDateFormatTest.java >___________________________________________________________________ >Added: svn:keywords > + Author Date Id Revision >Added: svn:eol-style > + native > >Index: src/main/java/org/apache/log4j/helpers/AbsoluteTimeDateFormat.java >=================================================================== >--- src/main/java/org/apache/log4j/helpers/AbsoluteTimeDateFormat.java (revision 783381) >+++ src/main/java/org/apache/log4j/helpers/AbsoluteTimeDateFormat.java (working copy) >@@ -69,6 +69,7 @@ > > private static long previousTime; > private static char[] previousTimeWithoutMillis = new char[9]; // "HH:mm:ss." >+ private static TimeZone previousTimeZone; > > /** > Appends to <code>sbuf</code> the time in the format >@@ -85,7 +86,7 @@ > long now = date.getTime(); > int millis = (int)(now % 1000); > >- if ((now - millis) != previousTime) { >+ if ((now - millis) != previousTime || !getTimeZone().equals(previousTimeZone)) { > // We reach this point at most once per second > // across all threads instead of each time format() > // is called. This saves considerable CPU time. >@@ -119,6 +120,7 @@ > sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0); > > previousTime = now - millis; >+ previousTimeZone = getTimeZone(); > } > else { > sbuf.append(previousTimeWithoutMillis); >Index: src/main/java/org/apache/log4j/helpers/ISO8601DateFormat.java >=================================================================== >--- src/main/java/org/apache/log4j/helpers/ISO8601DateFormat.java (revision 783381) >+++ src/main/java/org/apache/log4j/helpers/ISO8601DateFormat.java (working copy) >@@ -53,6 +53,7 @@ > > static private long lastTime; > static private char[] lastTimeString = new char[20]; >+ static private TimeZone lastTimeZone; > > /** > Appends a date in the format "YYYY-mm-dd HH:mm:ss,SSS" >@@ -67,7 +68,7 @@ > long now = date.getTime(); > int millis = (int)(now % 1000); > >- if ((now - millis) != lastTime) { >+ if ((now - millis) != lastTime || !getTimeZone().equals(lastTimeZone)) { > // We reach this point at most once per second > // across all threads instead of each time format() > // is called. This saves considerable CPU time. >@@ -129,6 +130,7 @@ > // store the time string for next time to avoid recomputation > sbuf.getChars(start, sbuf.length(), lastTimeString, 0); > lastTime = now - millis; >+ lastTimeZone = getTimeZone(); > } > else { > sbuf.append(lastTimeString);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 47350
:
23789
|
23793
|
23809