Skip to content

Document the PatternLayout date time zone and strftime options - #857

Open
NopeCharon wants to merge 1 commit into
apache:masterfrom
NopeCharon:document_date_pattern_options
Open

NopeCharon wants to merge 1 commit into
apache:masterfrom
NopeCharon:document_date_pattern_options

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Closes #856

Problem

The d row of the PatternLayout conversion table leaves out two options that DatePatternConverter already supports. They are only described in the DatePatternConverter constructor documentation:

  • A second set of braces selects the time zone. This is how to get UTC timestamps (%d{ISO8601}{GMT}) or a fixed offset (%d{HH:mm}{GMT+10}, %d{HH:mm}{GMT-05:30}). Without it, the local time zone is always used.
  • A date format specifier containing % is formatted with strftime, e.g. %d{%Y-%m-%d %H:%M:%S}.

The date alias of d was not listed either.

Change

The d row now has a paragraph for each option with an example, and lists the date alias. The change is documentation only.

Testing

I checked the documented behaviour with a program linked against the current master, run with TZ=America/New_York (local time 22:51, UTC 03:51):

Pattern Output
%d{ISO8601} 2026-12-04 22:51:01,982
%d{ISO8601}{GMT} 2026-12-05 03:51:01,983
%d{HH:mm}{GMT+10} 13:51
%d{HH:mm}{GMT-05:30} 22:21
%d{%Y-%m-%d %H:%M:%S} 2026-12-04 22:51:01
%d{%Y-%m-%d %H:%M:%S}{GMT} 2026-12-05 03:51:01

PatternParserTestCase::testMultiOption already covers the time zone option.

DatePatternConverter accepts a second option selecting the time zone
(GMT or an offset from GMT such as GMT+10 or GMT-05:30) and formats the
date using strftime when the date format specifier contains a '%'
character. Both options were only described in the DatePatternConverter
constructor documentation, so the PatternLayout reference gave no way to
discover how to output timestamps in UTC.

Describe both options, with examples, in the "d" row of the
PatternLayout conversion table and list the "date" alias.

Fixes apache#856
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.

Document the PatternLayout date time zone and strftime options

1 participant