Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOG4J2-3019: Fix HtmlLayoutTest on Windows #800

Closed
wants to merge 1 commit into from

Conversation

LF-Lin
Copy link
Contributor

@LF-Lin LF-Lin commented Mar 16, 2022

This PR fixes the issue that HtmlLayoutTest.testLayoutWithDatePatternFixedFormat test fails on Windows.

AFAIK, this test only fails in a special case on Windows, that is, the Windows display language and Regional format are inconsistent. For example, my settings are:

Windows display language: zh_CN
Regional format: en_NL

the result will be: [ERROR] HtmlLayoutTest.testLayoutWithDatePatternFixedFormat:245->testLayoutWithDatePatternFixedFormat:277 Incorrect date=<td>02 十一月 2012 21:34:02,123</td>, format=DATE, timezone=GMT+8 ==> expected: <<td>02 Nov 2012 21:32,123</td>> but was: <<td>02 十一月 2012 21:34:02,123</td>>


I think the reason is that

  • the actual value that generated from layout at line 255 using Locale.getDefault() (zh_CN, which causes 02 十一月),
  • the expected value that generated from DateTimeFormatter.ofPattern() at line 269 using Locale.Category.FORMAT (en_NL, which causes 02 Nov).

It is easy to avoid this issue by manually setting the locale argument for DateTimeFormatter.ofPattern(), and the results will use the Locale.getDefault().

@LF-Lin
Copy link
Contributor Author

LF-Lin commented Mar 16, 2022

Also, I reproduced the result in this issue by adding the following lines in testLayoutWithDatePatternFixedFormat(),

Locale.setDefault(new Locale("en", "NL"));  // en_NL --> 02 Nov
Locale.setDefault(Locale.Category.FORMAT, new Locale("nl", "NL"));  // nl_NL --> 02 nov

the result will be: [ERROR] HtmlLayoutTest.testLayoutWithDatePatternFixedFormat:242->testLayoutWithDatePatternFixedFormat:273 Incorrect date=<td>02 Nov 2012 21:34:02,123</td>, format=DATE, timezone=GMT+8 ==> expected: <<td>02 nov 2012 21:34:02,123</td>> but was: <<td>02 Nov 2012 21:34:02,123</td>>

@garydgregory
Copy link
Member

Hi @LF-Lin
Thank you for your PR. In order to make this use-case more obvious in the test, I choose a different implementation; please pull the branch and try your local build. Let us know what your results are.
TY!

@LF-Lin
Copy link
Contributor Author

LF-Lin commented Mar 16, 2022

Hi @LF-Lin Thank you for your PR. In order to make this use-case more obvious in the test, I choose a different implementation; please pull the branch and try your local build. Let us know what your results are. TY!

Nice implementation. Test passes!

@garydgregory
Copy link
Member

Closing, per @LF-Lin 's comment.
TY!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants