Skip to content

Fixing Issue-915#916

Merged
McDutchie merged 4 commits intoksh93:devfrom
phidebian:bug-182-4
Jan 28, 2026
Merged

Fixing Issue-915#916
McDutchie merged 4 commits intoksh93:devfrom
phidebian:bug-182-4

Conversation

@phidebian
Copy link
Copy Markdown

commit 1a9d8ad introduced a bug
printf "%(%Y-%m-%d)T\n" "now in 10 week"
produce
2025-11-13
This fix produce the expecteed
2026-01-22

src/lib/libast/tm/tmxdate.c::1456
case TM_PARTS+4:
tm = tmxtm(tm, tmxtime(tm, zone), tm->tm_zone, 0);
tm->tm_hour += m * 7 * 24;
set |= DAY; <======= TYPO HERE
goto clear_hour;

Since we are updating tm_hour then set HOUR

printf "%(%Y-%m-%d)T\n" "now in 10 week"
produce
2025-11-13
This fix produce the expecteed
2026-01-22

src/lib/libast/tm/tmxdate.c::1456
case TM_PARTS+4:
     tm = tmxtm(tm, tmxtime(tm, zone), tm->tm_zone, 0);
     tm->tm_hour += m * 7 * 24;
     set |= DAY; <======= TYPO HERE
goto clear_hour;

Since we are updating tm_hour then set HOUR
@McDutchie
Copy link
Copy Markdown

It still seems very buggy.

Today is 2026-01-22.

$ printf "%(%Y-%m-%d)T\n" "10 weeks"
2026-04-02
printf "%(%Y-%m-%d)T\n" "now in 10 weeks"
2026-04-02

So far, so good. But:

$ printf "%(%Y-%m-%d)T\n" "2026-01-21 in 10 weeks"                                                
2026-04-02
$ printf "%(%Y-%m-%d)T\n" "2026-01-20 in 10 weeks"
2026-04-02
$ printf "%(%Y-%m-%d)T\n" "2026-01-01 in 10 weeks"
2026-04-02
$ printf "%(%Y-%m-%d)T\n" "2025-31-01 in 10 weeks"
2025-04-11
$ printf "%(%Y-%m-%d)T\n" "2025-01-01 in 10 weeks"
2025-04-02

None of that makes any sense, does it?

@phidebian
Copy link
Copy Markdown
Author

@McDutchie Yes it was very very buggy and now it is very buggy, I doubt anyone use that.

Yet it is still possible to do the math the right way $((...)) arith instead of the cobol like "now in 10 weeks".

The following shows how to get 'now" then add up whatever formula you need.
(Any online IA will produce that formula ;-) )

TC$ printf -v now '%(%s)T' now ; echo $now
1769147179

TC$ then=$((now+(10*7*24*60*60))) ; echo $then
1775195179

TC$ printf "%(%Y-%m-%d %H:%M:%S %s.%N)T\n" $now.000000000 
2026-01-23 05:46:19 1769147179.000000000

TC$ printf "%(%Y-%m-%d %H:%M:%S %s.%N)T\n" $then.000000000
2026-04-03 05:46:19 1775195179.000000000

TC$ date +"%Y-%m-%d %H:%M:%S %s.%N" --date=@$then                           
2026-04-03 07:46:19 1775195179.000000000

Use this as a workaround until someone fix this bug...

@phidebian
Copy link
Copy Markdown
Author

@McDutchie Welcome back by the way :-)

@McDutchie
Copy link
Copy Markdown

Thanks. :)

I can't easily think of a regression test since the result changes by the day, so I'll just merge this now.

@McDutchie McDutchie merged commit 83c51b1 into ksh93:dev Jan 28, 2026
McDutchie pushed a commit that referenced this pull request Jan 28, 2026
The referenced commit introduced a bug:
    printf "%(%Y-%m-%d)T\n" "now in 10 week"
    printf "%(%Y-%m-%d)T\n" "in 10 weeks"
produce today's date.
As of this fix, they produce the date in ten weeks.

src/lib/libast/tm/tmxdate.c::1456
	case TM_PARTS+4:
	     tm = tmxtm(tm, tmxtime(tm, zone), tm->tm_zone, 0);
	     tm->tm_hour += m * 7 * 24;
	     set |= DAY; // <======= BUG HERE
	goto clear_hour;

The fix: since we are updating tm_hour, set HOUR, not DAY.

Resolves: #915
McDutchie pushed a commit that referenced this pull request Jan 28, 2026
The referenced commit introduced a bug:
    printf "%(%Y-%m-%d)T\n" "now in 10 week"
    printf "%(%Y-%m-%d)T\n" "in 10 weeks"
produce today's date.
As of this fix, they produce the date in ten weeks.

src/lib/libast/tm/tmxdate.c::1456
	case TM_PARTS+4:
	     tm = tmxtm(tm, tmxtime(tm, zone), tm->tm_zone, 0);
	     tm->tm_hour += m * 7 * 24;
	     set |= DAY; // <======= BUG HERE
	goto clear_hour;

The fix: since we are updating tm_hour, set HOUR, not DAY.

Resolves: #915
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants