1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix failure to zero pad with 'printf %(%0l)T' (re: 9526b3fa) (#107)

src/lib/libast/tm/tmxfmt.c:
- Making %l and %k aliases to %_I and %_H caused zero padding with
  %0l and %0k to fail. Fix that by fully implementing %l and %k
  without 'goto push'. This duplicates code from %I and %H, but it
  is necessary for these formats to work correctly when zero padded.

src/cmd/ksh93/tests/builtins.sh:
- Add a regression test for manually specifying blank and zero
  padding with sixteen different formats.
This commit is contained in:
Johnothan King 2020-08-05 09:52:21 -07:00 committed by GitHub
parent 07b240d4f9
commit 83996d5a8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View file

@ -316,9 +316,9 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
case 'J': /* Julian date (0 offset) */
cp = number(cp, ep, (long)tm->tm_yday, 3, width, pad);
continue;
case 'k': /* hour (0 - 23) with blank padding */
p = "%_H";
goto push;
case 'k': /* hour (0 - 23) with blank padding (can't be an alias to %_H) */
cp = number(cp, ep, (long)tm->tm_hour, -2, width, pad);
continue;
case 'K': /* (AST) largest to smallest */
switch (alt)
{
@ -333,9 +333,11 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
break;
}
goto push;
case 'l': /* hour (0 - 12) with blank padding */
p = "%_I";
goto push;
case 'l': /* hour (0 - 12) with blank padding (can't be an alias to %_I) */
if ((n = tm->tm_hour) > 12) n -= 12;
else if (n == 0) n = 12;
cp = number(cp, ep, (long)n, -2, width, pad);
continue;
case 'L': /* (AST) OBSOLETE use %Ql */
p = "%Ql";
goto push;