You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
~_ print ${.sh.version}
Version JM 93u+m/1.1.0-alpha+0f6866b6/MOD 2025-06-22
~_ printf '%(%Y)T\n' "Dec 20"
2026
~_ printf '%(%Y)T\n' "Jan 20"
2026
~_ printf '%(%Y)T\n' "Jan"
2025
~_ date -d "Dec 20" +%Y
2026
~_ date -d "Dec" +%Y
2025
~_ whence -a date
date is a shell builtin
date is /usr/bin/date
"Month day" input gives next year, not current. Same error also on AIX:
~> print -f '%(%Y)T\n' "Jan 20"
2026
~> print ${.sh.version}
Version JM 93u+m/1.1.0-alpha 2025-06-22
~> uname
AIX
Bug appears also in Version JM 93u+m/1.0.10 2024-08-01
Workaround is to use "first":
~_ print -f '%(%Y)T\n' "first Dec 20"
2025
~_ date -d "first Dec 20" +%Y
2025
# ksh -c 'printf "%T\n" 2026-01-01'
Thu ELF 1 21:41:50 MET 2026
# ksh -c 'printf "%T\n"'
Wed ELF 14 21:42:36 MET 2026
# ksh -c 'printf "%T\n" 2026-02-01'
Sun Feb 1 21:43:25 MET 2026
What locale is this? Anyway, I cannot confirm:
~_ ksh -c 'printf "%T\n" 2026-01-01'
Thu Jan 1 00:10:39 CET 2026
~_ ksh -c 'LC_TIME=C printf "%T\n" 2026-01-01'
Thu Jan 1 00:10:50 CET 2026
~_ ksh -c 'printf "%T\n"'
Thu Jan 15 00:11:12 CET 2026
~_ ksh -c 'LC_TIME=C printf "%T\n" 2026-02-01'
Sun Feb 1 00:11:24 CET 2026
~_ ksh -c 'LC_TIME=de_DE printf "%T\n" 2026-02-01'
So 1. Feb 00:12:14 CET 2026
~_ ksh -c 'LC_TIME=de_DE printf "%T\n" 2026-01-01'
Do 1. Jan 00:12:18 CET 2026
I can't look at the moment, surgery recovery, you may error/try other factor, I don't remember why I used 1, if this is really me introduced it. I remember this code was hard to follow and may be I overlooked some corner cases...
Not sure. Might be even older: Checked an old Solaris machine with a Sun/Oracle patched Version AJM 93u+ 2012-08-01 ksh on it - same behavior, i.e. YYYY-01-DD => %{b,h,Ec} == *ELF*, but %B seems to be ok. Unfortunately have no time to make a deep dive, too. :(
I've confirmed that this is the commit that introduces the bug. It's unfortunate, because that commit fixes a load of other bugs, so we can't just revert it.
I've tried changing the default value of f to 0 and that seems to fix the issue, but causes dozens of regression test failures in printf.sh, so it's clearly not correct.
I'll note that those two lines weren't added by the commit in question; they're original. However, they may have been somehow rendered incorrect by that commit. I'm going to have to spend some time trying to actually understand all this code, but it's very difficult.
Ping @pghvlaans: Would you happen to have time to take a look at this tm(3) issue as well? Reproducer at the top (just add a year). There are a couple of patch ideas above but I'm not confident about them.
Basically, that (f > 0) condition expects a baseline value of f = 0. This would make plain "Month Day" requests have f of 0. The baseline can't be changed without lots of other breakage, though. There might be something else bumping the year when it shouldn't, but I haven't managed to track it down just yet.
The "Jun 23" and "Jul 23" thing I mentioned earlier is actually just down to a lack of resolution in lines 1671 and 1673, so it isn't entirely related.
I've made a fair amount of progress on my tmxdate branch. The following problems have been solved:
The wrong "Month Day" year
e.g. third dec failing to work
e.g. third dec 10 being a year ahead
next does not correspond to GNU date for days of the week; it's also too aggressive for months, though date doesn't handle that.
second jan (day) failing to recognize second as ordinal
e.g. 2020-2-3 next fri is off by weeks
There are other pending issues I intend to get to before making a PR (though more may come to light):
e.g. 2020-2-3 next fri is off by weeks
There is insufficient resolution to recognize whether a day has passed in the current month. second jul 10 and second jul 30 should ideally have different years when called on July 26th, and they don't.
Activity
jelmd commentedon Jan 14, 2026
pgtan commentedon Jan 14, 2026
What locale is this? Anyway, I cannot confirm:
jelmd commentedon Jan 16, 2026
jelmd commentedon Jan 16, 2026
JohnoKing commentedon Feb 11, 2026
This seems to have been introduced in 1a9d8ad by setting the default factor to one (ping @phidebian):
ksh/src/lib/libast/tm/tmxdate.c
Lines 234 to 236 in 79ad217
phidebian commentedon Feb 11, 2026
I can't look at the moment, surgery recovery, you may error/try other factor, I don't remember why I used 1, if this is really me introduced it. I remember this code was hard to follow and may be I overlooked some corner cases...
jelmd commentedon Feb 12, 2026
Not sure. Might be even older: Checked an old Solaris machine with a Sun/Oracle patched
Version AJM 93u+ 2012-08-01ksh on it - same behavior, i.e.YYYY-01-DD => %{b,h,Ec} == *ELF*, but %B seems to be ok. Unfortunately have no time to make a deep dive, too. :(McDutchie commentedon Apr 2, 2026
I've confirmed that this is the commit that introduces the bug. It's unfortunate, because that commit fixes a load of other bugs, so we can't just revert it.
I've tried changing the default value of
fto 0 and that seems to fix the issue, but causes dozens of regression test failures in printf.sh, so it's clearly not correct.phidebian commentedon Apr 2, 2026
JohnoKing commentedon Apr 2, 2026
Here's my attempt at fixing it (uncertain of correctness):
McDutchie commentedon Apr 2, 2026
Ha, I had just arrived at the exact same point in the code by tagging everything that handles tm_year with debug
sfprintfs. :)Yes, lines 1556-1557 is where this bug happens.
My patch was to simply remove that:
No regression test failures happen after that (neither in printf.sh nor elsewhere). But I'm also not sure of the correctness.
McDutchie commentedon Apr 2, 2026
I'll note that those two lines weren't added by the commit in question; they're original. However, they may have been somehow rendered incorrect by that commit. I'm going to have to spend some time trying to actually understand all this code, but it's very difficult.
McDutchie commentedon Jul 25, 2026
Ping @pghvlaans: Would you happen to have time to take a look at this tm(3) issue as well? Reproducer at the top (just add a year). There are a couple of patch ideas above but I'm not confident about them.
pghvlaans commentedon Jul 25, 2026
I'll see what I can do.
pghvlaans commentedon Jul 25, 2026
I can confirm that neither patch is correct, unfortunately. To reproduce, try
printf "%(%Y)T" "third Dec 20". The output should be 2028.McDutchie commentedon Jul 25, 2026
The fact that using "first" is a workaround may provide a clue to a fix -- if you can find where/how that is processed.
McDutchie commentedon Jul 25, 2026
However... it seems like
second,third, etc., are also broken.pghvlaans commentedon Jul 25, 2026
Well, this does appear to work:
I'm a bit suspicious, though, since
fis apparently1without an ordinal and0withfirst. It could very well be something far sillier (and messier).EDIT: It does not work.
next Jul 23andnext Jun 23shouldn't have different output, and with this (and the current code), they do.pghvlaans commentedon Jul 25, 2026
Something along these lines would be better:
Basically, that
(f > 0)condition expects a baseline value off = 0. This would make plain "Month Day" requests havefof0. The baseline can't be changed without lots of other breakage, though. There might be something else bumping the year when it shouldn't, but I haven't managed to track it down just yet.The "Jun 23" and "Jul 23" thing I mentioned earlier is actually just down to a lack of resolution in lines 1671 and 1673, so it isn't entirely related.
I'll take another look tomorrow.
pghvlaans commentedon Jul 26, 2026
Also found this, which was causing
secondto not be recognized as an ordinal with the abbreviationjan:pghvlaans commentedon Jul 26, 2026
I've made a fair amount of progress on my tmxdate branch. The following problems have been solved:
third decfailing to workthird dec 10being a year aheadnextdoes not correspond to GNUdatefor days of the week; it's also too aggressive for months, thoughdatedoesn't handle that.second jan (day)failing to recognizesecondas ordinal2020-2-3 next friis off by weeksThere are other pending issues I intend to get to before making a PR (though more may come to light):
e.g.2020-2-3 next friis off by weekssecond jul 10andsecond jul 30should ideally have different years when called on July 26th, and they don't.McDutchie commentedon Sep 1, 2026
Any luck on the pending issues, @pghvlaans? Let me know if I can be of any help.
pghvlaans commentedon Sep 1, 2026
Hey, sorry, I've been busy, but I'll have a chance to have another good look this week. I'll let you know if anything comes up.