From e83553d9dce1638210d9ee24514cf6c3a9826c80 Mon Sep 17 00:00:00 2001 From: Phi Date: Sat, 30 Mar 2024 14:07:46 +0100 Subject: [PATCH] printf %T: Fix "th" as ordinal specifier (re: 1a9d8ada) (#734) Reproducers: $ printf '%(%F)T\n' '4th tuesday in march 2016' 2016-04-09 $ printf '%(%F)T\n' '4nd tuesday in march 2016' 2016-03-08 Expected, in both cases: 2016-03-22 It was a left over, while I reworked these things some time ago, I normalised the 'f' variable usage (specially the +1 -1 usage), and the cryptic TM_ORDINAL case was kinda magical and I left it untouched. Now thanx @stephane-chazelas, I got a test case and can understand it. I added a test case to catch any regression in this area if one try to make printf better :-) src/lib/libast/tm/tmxdate.c: - tmxdate(): While normalising the 'f' variable usage into tmxdate(), also handle the TM_ORDINAL case, which had been overlooked. Thanks to @stephane-chazelas for the bug report. Resolves: https://github.com/ksh93/ksh/issues/733 --- NEWS | 8 ++++++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/tests/printf.sh | 18 ++++++++++++++++++ src/lib/libast/Mamfile | 11 ----------- src/lib/libast/tm/tmxdate.c | 2 +- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index db025f43bdd8..b5cdd0beb309 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,14 @@ This documents significant changes in the dev branch of ksh 93u+m. For full details, see the git log at: https://github.com/ksh93/ksh Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library. +2024-03-30: + +- A regression was fixed in ordinal specifiers in 'printf %T' date + specifications. For example, + printf '%(%F)T\n' '4th tuesday in march 2016' + wrongly printed '2016-04-09' and now again correctly prints '2016-03-22'. + This regression was introduded with the printf fixes on 2023-05-18. + 2024-03-24: - We now support building a dynamically linked ksh 93u+m with libast, diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 7c95a8db3233..3287bff06fee 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -18,7 +18,7 @@ #define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */ #define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */ -#define SH_RELEASE_DATE "2024-03-24" /* must be in this format for $((.sh.version)) */ +#define SH_RELEASE_DATE "2024-03-30" /* must be in this format for $((.sh.version)) */ #define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK /* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */ diff --git a/src/cmd/ksh93/tests/printf.sh b/src/cmd/ksh93/tests/printf.sh index da6e470ffe96..42faa0dcd322 100755 --- a/src/cmd/ksh93/tests/printf.sh +++ b/src/cmd/ksh93/tests/printf.sh @@ -285,6 +285,24 @@ T '2020-2-3 12:34:56 next fri' '2020-02-14 12:34:56' T '2020-2-3T12:34:56Z' '2020-02-03 12:34:56' T '2020-2-3 12:34:56Z' '2020-02-03 12:34:56' +C='Ordinal access' +format='%F' +T '1th tuesday in 2016-3' '2016-03-01' +T '2th tuesday in 2016-3' '2016-03-08' +T '3th tuesday in 2016-3' '2016-03-15' +T '4th tuesday in 2016-3' '2016-03-22' +T '5th tuesday in 2016-3' '2016-03-29' +T 'first tuesday in march 2016' '2016-03-01' +T 'second tuesday in march 2016' '2016-03-08' +T 'third tuesday in march 2016' '2016-03-15' +T 'fourth tuesday in march 2016' '2016-03-22' +T 'fifth tuesday in march 2016' '2016-03-29' +T '1st tuesday in march 2016' '2016-03-01' +T '2nd tuesday in march 2016' '2016-03-08' +T '3rd tuesday in march 2016' '2016-03-15' +T '4th tuesday in march 2016' '2016-03-22' +T '5th tuesday in march 2016' '2016-03-29' + # The following tests for times relative to the current time require GNU 'date' to compare our results to. if ! gd=$( set -o noglob IFS=: diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 6e6d5daf2907..0af0b6f8ed63 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -5067,17 +5067,6 @@ make install virtual exec - (set +f; exec rm -rf ${INSTALLROOT}/bin/${@} ${INSTALLROOT}/bin/${@}.*) exec - cp ${@} ${INSTALLROOT}/bin/${@} done - - note * - note * Dynamically linked version, if supported - note * - - make ${INSTALLROOT}/dyn/bin/mamake dontcare - prev mamake - prev ${INSTALLROOT}/lib/lib/ast - exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}' - exec - dylink -e mamake ${mam_libutil} $(cat ${INSTALLROOT}/lib/lib/ast) mamake.o - done done install make test dontcare virtual diff --git a/src/lib/libast/tm/tmxdate.c b/src/lib/libast/tm/tmxdate.c index 29d6ec1798f4..f5eced5240b3 100644 --- a/src/lib/libast/tm/tmxdate.c +++ b/src/lib/libast/tm/tmxdate.c @@ -805,7 +805,7 @@ tmxdate(const char* s, char** e, Time_t now) break; goto save; } - else if (f == -1 && isalpha(*t) && tmlex(t, &t, tm_info.format + TM_ORDINAL, TM_ORDINALS - TM_ORDINAL, NULL, 0) >= 0) + else if ((f == -1 || f == 1) && isalpha(*t) && tmlex(t, &t, tm_info.format + TM_ORDINAL, TM_ORDINALS - TM_ORDINAL, NULL, 0) >= 0) { message((-1, "AHA#%d n=%d", __LINE__, n)); ordinal: