Skip to content

Commit e83553d

Browse files
phidebianMcDutchie
authored andcommitted
printf %T: Fix "th" as ordinal specifier (re: 1a9d8ad) (#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: #733
1 parent 2e849e6 commit e83553d

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

NEWS

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ This documents significant changes in the dev branch of ksh 93u+m.
22
For full details, see the git log at: https://github.com/ksh93/ksh
33
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
44

5+
2024-03-30:
6+
7+
- A regression was fixed in ordinal specifiers in 'printf %T' date
8+
specifications. For example,
9+
printf '%(%F)T\n' '4th tuesday in march 2016'
10+
wrongly printed '2016-04-09' and now again correctly prints '2016-03-22'.
11+
This regression was introduded with the printf fixes on 2023-05-18.
12+
513
2024-03-24:
614

715
- We now support building a dynamically linked ksh 93u+m with libast,

src/cmd/ksh93/include/version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
2020
#define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */
21-
#define SH_RELEASE_DATE "2024-03-24" /* must be in this format for $((.sh.version)) */
21+
#define SH_RELEASE_DATE "2024-03-30" /* must be in this format for $((.sh.version)) */
2222
#define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK
2323

2424
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

src/cmd/ksh93/tests/printf.sh

+18
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ T '2020-2-3 12:34:56 next fri' '2020-02-14 12:34:56'
285285
T '2020-2-3T12:34:56Z' '2020-02-03 12:34:56'
286286
T '2020-2-3 12:34:56Z' '2020-02-03 12:34:56'
287287

288+
C='Ordinal access'
289+
format='%F'
290+
T '1th tuesday in 2016-3' '2016-03-01'
291+
T '2th tuesday in 2016-3' '2016-03-08'
292+
T '3th tuesday in 2016-3' '2016-03-15'
293+
T '4th tuesday in 2016-3' '2016-03-22'
294+
T '5th tuesday in 2016-3' '2016-03-29'
295+
T 'first tuesday in march 2016' '2016-03-01'
296+
T 'second tuesday in march 2016' '2016-03-08'
297+
T 'third tuesday in march 2016' '2016-03-15'
298+
T 'fourth tuesday in march 2016' '2016-03-22'
299+
T 'fifth tuesday in march 2016' '2016-03-29'
300+
T '1st tuesday in march 2016' '2016-03-01'
301+
T '2nd tuesday in march 2016' '2016-03-08'
302+
T '3rd tuesday in march 2016' '2016-03-15'
303+
T '4th tuesday in march 2016' '2016-03-22'
304+
T '5th tuesday in march 2016' '2016-03-29'
305+
288306
# The following tests for times relative to the current time require GNU 'date' to compare our results to.
289307
if ! gd=$( set -o noglob
290308
IFS=:

src/lib/libast/Mamfile

-11
Original file line numberDiff line numberDiff line change
@@ -5067,17 +5067,6 @@ make install virtual
50675067
exec - (set +f; exec rm -rf ${INSTALLROOT}/bin/${@} ${INSTALLROOT}/bin/${@}.*)
50685068
exec - cp ${@} ${INSTALLROOT}/bin/${@}
50695069
done
5070-
5071-
note *
5072-
note * Dynamically linked version, if supported
5073-
note *
5074-
5075-
make ${INSTALLROOT}/dyn/bin/mamake dontcare
5076-
prev mamake
5077-
prev ${INSTALLROOT}/lib/lib/ast
5078-
exec - export LDFLAGS='${LDFLAGS} ${CCLDFLAGS} ${mam_cc_LD_NOASNEEDED}'
5079-
exec - dylink -e mamake ${mam_libutil} $(cat ${INSTALLROOT}/lib/lib/ast) mamake.o
5080-
done
50815070
done install
50825071

50835072
make test dontcare virtual

src/lib/libast/tm/tmxdate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ tmxdate(const char* s, char** e, Time_t now)
805805
break;
806806
goto save;
807807
}
808-
else if (f == -1 && isalpha(*t) && tmlex(t, &t, tm_info.format + TM_ORDINAL, TM_ORDINALS - TM_ORDINAL, NULL, 0) >= 0)
808+
else if ((f == -1 || f == 1) && isalpha(*t) && tmlex(t, &t, tm_info.format + TM_ORDINAL, TM_ORDINALS - TM_ORDINAL, NULL, 0) >= 0)
809809
{
810810
message((-1, "AHA#%d n=%d", __LINE__, n));
811811
ordinal:

0 commit comments

Comments
 (0)