This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new 401017e4a9 Fixing HtmlLayoutTest when timezone has minutes (#1127)
401017e4a9 is described below
commit 401017e4a90b0890b8cf3966d5049d8bda6033cb
Author: Adwait Kumar Singh <[email protected]>
AuthorDate: Fri Oct 28 20:44:57 2022 +0530
Fixing HtmlLayoutTest when timezone has minutes (#1127)
---
.../apache/logging/log4j/core/layout/HtmlLayoutTest.java | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
index f91deef96d..6437bfacde 100644
---
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
+++
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/layout/HtmlLayoutTest.java
@@ -39,6 +39,7 @@ import
org.apache.logging.log4j.core.test.BasicConfigurationFactory;
import org.apache.logging.log4j.core.test.appender.ListAppender;
import org.apache.logging.log4j.core.time.Instant;
import org.apache.logging.log4j.core.time.MutableInstant;
+import org.apache.logging.log4j.core.util.datetime.FixedDateFormat;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.SimpleMessage;
import org.apache.logging.log4j.test.junit.UsingAnyThreadContext;
@@ -238,13 +239,13 @@ public class HtmlLayoutTest {
@Test
public void testLayoutWithDatePatternFixedFormat() {
- for (final String timeZone : new String[] {"GMT+8", "UTC", null}) {
+ for (final String timeZone : new String[] {"GMT+8", "GMT+0530" ,"UTC",
null}) {
for (final FixedFormat format : FixedFormat.values()) {
testLayoutWithDatePatternFixedFormat(format, timeZone);
}
}
}
-
+
private String getDateLine(String logEventString) {
return logEventString.split(System.lineSeparator())[2];
}
@@ -269,7 +270,7 @@ public class HtmlLayoutTest {
// Locale.getDefault(Locale.Category.FORMAT)
final Locale formatLocale = Locale.getDefault(Locale.Category.FORMAT);
final Locale locale = Locale.getDefault().equals(formatLocale) ?
formatLocale : Locale.getDefault();
-
+
// For DateTimeFormatter of jdk,
// Pattern letter 'S' means fraction-of-second, 'n' means
nano-of-second. Log4j2 needs S.
// Pattern letter 'X' (upper case) will output 'Z' when the offset to
be output would be zero,
@@ -278,6 +279,15 @@ public class HtmlLayoutTest {
DateTimeFormatter.ofPattern(format.getPattern().replace('n',
'S').replace('X', 'x'), locale);
String expected = zonedDateTime.format(dateTimeFormatter);
+ String offset = zonedDateTime.getOffset().toString();
+
+ //Truncate minutes if timeZone format is HH and timeZone has minutes.
This is required because according to DateTimeFormatter,
+ //One letter outputs just the hour, such as '+01', unless the minute
is non-zero in which case the minute is also output, such as '+0130'
+ //ref :
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
+
if(FixedDateFormat.FixedTimeZoneFormat.HH.equals(format.getFixedTimeZoneFormat())
&& offset.contains(":") && !"00".equals(offset.split(":")[1])) {
+ expected = expected.substring(0, expected.length() - 2);
+ }
+
assertEquals("<td>" + expected + "</td>", actual,
MessageFormat.format("Incorrect date={0}, format={1},
timezone={2}", actual, format.name(), timezone));
}