Skip to content

Commit

Permalink
printf %T: Fix "th" as ordinal specifier (re: 1a9d8ad) (#734)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
phidebian authored and McDutchie committed Mar 30, 2024
1 parent 2e849e6 commit e83553d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/ksh93/tests/printf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=:
Expand Down
11 changes: 0 additions & 11 deletions src/lib/libast/Mamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/libast/tm/tmxdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e83553d

Please sign in to comment.