Skip to content

date: drop the seconds of an offset in %z and %:z like GNU - #17142

Open
zodrickjohn wants to merge 1 commit into
uutils:mainfrom
zodrickjohn:date-offset-seconds
Open

zodrickjohn wants to merge 1 commit into
uutils:mainfrom
zodrickjohn:date-offset-seconds

Conversation

@zodrickjohn

Copy link
Copy Markdown

Two differences from GNU in the numeric time zone conversions, both for the historical offsets of tzdata (before about 1970) and POSIX TZ values:

1. %z and %:z printed the seconds of an offset. jiff writes them when they are not zero; GNU has no seconds field in these two and drops them (it truncates: -00:44:30 is -0044, not -0045). %::z and %:::z keep them, as before.

$ TZ=Africa/Monrovia date -d @-1000000000 '+%z %:z %::z'
GNU 9.12:  -0044 -00:44 -00:44:30
before:    -004430 -00:44:30 -00:44:30

The two are now cut from %::z. A format without modifiers only takes the slower modifier path when the offset has seconds and the format contains a z.

2. - stripped an offset under an hour to three digits. GNU strips the digits of %z as one number:

$ TZ=AMT-0:20 date -d 2024-06-15 '+%-z %_z'
GNU 9.12:  +20   +20
before:    +020  +020

strip_timezone_hour_padding now strips everything before the first colon, which also covers the all-zero case it handled separately.

I compared GNU coreutils 9.12 with this branch on every flag (none, 0, _, -, +, ^, # and pairs) and widths 1 to 10 of the four conversions, in 10 zones (Africa/Monrovia 1938, America/New_York 1874, Europe/Dublin 1912, AMT-0:20, XST0:30, Asia/Kolkata, UTC, Pacific/Chatham, America/St_Johns, Pacific/Kiritimati). Together with #17141, which fixes the padding with a width or the +/^/# flags, all 3960 combinations match; the branches merge without conflicts. The new test uses POSIX TZ values, so it does not depend on tzdata, and it fails on main.

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