Skip to content

Conversation

@phidebian
Copy link

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

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
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
Author

@McDutchie Welcome back by the way :-)

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