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

Fix unexpected output from 'printf %T' with certain formats (#65)

This commit changes the behavior of four date formats accepted
by 'printf %()T' because the old behavior is not compatible with
modern implementations of date(1):
- %k and %l now return a blank-padded hour, the former based on a
  24-hour clock and the latter a 12-hour clock (these are common
  extensions present on Linux and *BSD).
- %f now returns a date with the format '%Y.%m.%d-%H:%M:%S'
  (BusyBox extension).
- %q now returns the quarter of the current year (GNU extension).

src/cmd/ksh93/data/builtins.c:
- Copy the date format documentation from date in libcmd to
  the printf man page (for documenting 'printf %T').

src/cmd/ksh93/tests/builtins.sh:
- Add four regression tests for the changed date formats.

src/cmd/ksh93/sh.1:
- Remove inaccurate information about the date formats accepted by
  printf %T'. The KornShell uses a custom version of strftime(3)
  that isn't guaranteed to accepts the same formats as the native
  strftime function.

src/lib/libast/tm/tmxfmt.c:
- Change the behavior of %f, %k, %l and %q to the common behavior.
  %k and %l are implemented as aliases to %_H and %_I to avoid
  duplicating code.

src/lib/libcmd/date.c:
- Update the documentation for the AST date command since it is
  also affected by the changes to 'printf %T'.

Fixes #62
This commit is contained in:
Johnothan King 2020-07-08 21:08:28 -07:00 committed by GitHub
parent e70925ce10
commit 9526b3fa08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 103 additions and 22 deletions

View file

@ -271,8 +271,8 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
case 'e': /* blank padded day of month */
cp = number(cp, ep, (long)tm->tm_mday, -2, width, pad);
continue;
case 'f': /* (AST) OBSOLETE use %Qf */
p = "%Qf";
case 'f': /* Output the date in a format compatible with BusyBox %f */
p = "%Y.%m.%d-%H:%M:%S";
goto push;
case 'F': /* ISO 8601:2000 standard date format */
p = "%Y-%m-%d";
@ -316,8 +316,8 @@ 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': /* (AST) OBSOLETE use %QD */
p = "%QD";
case 'k': /* hour (0 - 23) with blank padding */
p = "%_H";
goto push;
case 'K': /* (AST) largest to smallest */
switch (alt)
@ -333,8 +333,8 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
break;
}
goto push;
case 'l': /* (AST) OBSOLETE use %QL */
p = "%QL";
case 'l': /* hour (0 - 12) with blank padding */
p = "%_I";
goto push;
case 'L': /* (AST) OBSOLETE use %Ql */
p = "%Ql";
@ -364,9 +364,9 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
while (cp < ep && (n = *p++))
*cp++ = isupper(n) ? tolower(n) : n;
continue;
case 'q': /* (AST) OBSOLETE use %Qz */
p = "%Qz";
goto push;
case 'q': /* quarter of the year (1-4) */
cp = number(cp, ep, (long)(tm->tm_mon / 3) + 1, 0, width, pad);
continue;
case 'Q': /* (AST) %Q<alpha> or %Q<delim>recent<delim>distant<delim> */
if (c = *format)
{

View file

@ -95,26 +95,26 @@ USAGE_LICENSE
" [+d?day of month number]"
" [+D?date as \amm/dd/yy\a]"
" [+e?blank padded day of month number]"
" [+f?locale default override date format]"
" [+f?print a date with the format '\%Y.\%m.\%d-\%H:\%M:\%S']"
" [+F?%ISO 8601:2000 standard date format; equivalent to Y-%m-%d]"
" [+g?\bls\b(1) \b-l\b recent date with \ahh:mm\a]"
" [+G?\bls\b(1) \b-l\b distant date with \ayyyy\a]"
" [+h?abbreviated month name]"
" [+H?24-hour clock hour]"
" [+H?24-hour clock hour, zero-padded]"
" [+i?international \bdate\b(1) date with time zone type name]"
" [+I?12-hour clock hour]"
" [+I?12-hour clock hour, zero-padded]"
" [+j?1-offset Julian date]"
" [+J?0-offset Julian date]"
" [+k?\bdate\b(1) style date]"
" [+k?24-hour clock hour, blank-padded]"
" [+K?all numeric date; equivalent to \b%Y-%m-%d+%H:%M:%S\b; \b%_[EO]]K\b for space separator, %OK adds \b.%N\b, \b%EK\b adds \b%.N%z\b, \b%_EK\b adds \b.%N %z\b]"
" [+l?\bls\b(1) \b-l\b date; equivalent to \b%Q/%g/%G/\b]"
" [+l?12-hour clock hour, blank-padded]"
" [+L?locale default date format]"
" [+m?month number]"
" [+M?minutes]"
" [+n?newline character]"
" [+N?nanoseconds 000000000-999999999]"
" [+p?meridian (e.g., \bAM\b or \bPM\b)]"
" [+q?time zone type name (nation code)]"
" [+q?quarter of the year]"
" [+Q?\a<del>recent<del>distant<del>\a: \a<del>\a is a unique"
" delimter character; \arecent\a format for recent"
" dates, \adistant\a format otherwise]"