Skip to content

date: pad numeric time zones like GNU when given a width or flag - #17141

Open
zodrickjohn wants to merge 1 commit into
uutils:mainfrom
zodrickjohn:date-timezone-width
Open

zodrickjohn wants to merge 1 commit into
uutils:mainfrom
zodrickjohn:date-timezone-width

Conversation

@zodrickjohn

Copy link
Copy Markdown

With a field width, or with the +, ^ or # flags, the numeric time zone conversions (%z, %:z, %::z, %:::z) were formatted differently from GNU:

TZ=Asia/Kolkata GNU 9.12 before after
%3z +530 +0530 +530
%+6z +00530 +0530 +00530
%2:z +5:30 +05:30 +5:30
%_:::z +5:30 +5:30 +5:30
%3z with TZ=UTC0 +00 +0000 +00

GNU first strips the zero padding of the hour, then pads the offset to the width (the width of the unmodified offset when none is given): with zeros after the sign, or with spaces before it under _; - disables the padding. Only - and _ used to strip the hour, only 0 padded with zeros, and a width alone went through the generic path. apply_timezone_modifiers now handles every flag and width this way, and timezone_default_width is no longer needed.

I compared GNU coreutils 9.12 and this branch on 3696 combinations (7 zones including +13:45 and -3:30, flags none/0/_/-/+/^/# and pairs of them, widths 1 to 12) and they all match; on main 604 of the first 1400 differed. The new test fails on main.

Separate, not changed here: for an offset with seconds (e.g. TZ=Africa/Monrovia date -d @-1000000000), plain %z and %:z print the seconds (-004430), where GNU prints -0044.

This branch has not been deployed

No deployments
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.

1 participant