More than a year ago, I wrote td.sh. It is very helpful to me, I use it to show the uptime and the Portage tree's freshness. I recently moved it to GitHub, even it's only one short script, less than 100 hundred lines, 19 of them are MIT License text. It deserves its own repository.

It's fairly easy to use, you just feed it the number of seconds.

After moving to GitHub, I added a few features because there was a picky alignment issue from me. I have a script which records Unix timestamps, it calculate those timestamps to current time and show the ages using td.sh. They are not aligned and it looks really ugly as you see in the first case below.

$ ./td.sh 1 2 60 61
1 second
2 seconds
1 minute
1 minute 1 second
$ ./td.sh -p -P 1 2 60 61
1 second
2 seconds
1 minute
1 minute 1 second
$ ./td.sh -p -P -a 1 2 60 61
0 days 0 hours 0 minutes 1 second
0 days 0 hours 0 minutes 2 seconds
0 days 0 hours 1 minute 0 seconds
0 days 0 hours 1 minute 1 second

Now it looks great. Also I updated the test script:

$ ./td-test.sh 
Passed: 0 => "0 seconds"
Passed: 1 => "1 second"
Passed: -1 => "1 second"
Passed: 2 => "2 seconds"
Passed: 60 => "1 minute"
Passed: 61 => "1 minute 1 second"
Passed: 3599 => "59 minutes 59 seconds"
Passed: 3600 => "1 hour"
Passed: 3601 => "1 hour 1 second"
Passed: 3660 => "1 hour 1 minute"
Passed: 3661 => "1 hour 1 minute 1 second"
Passed: 86400 => "1 day"
Passed: 172799 => "1 day 23 hours 59 minutes 59 seconds"
Passed: 259199 => "2 days 23 hours 59 minutes 59 seconds"
Passed: 31622401 => "366 days 1 second"
Passed: 1 -P => "1 second "
Passed: 60 -P => "1 minute "
Passed: 60 -P -p => " 1 minute "
Passed: 60 -P -p0 => "01 minute "
Passed: 60 -p -a => " 0 days 0 hours 1 minute 0 seconds"
Passed: 60 -P -a => "0 days 0 hours 1 minute 0 seconds"
Passed: 60 -P -p -a => " 0 days 0 hours 1 minute 0 seconds"
0 failures of 22 tests.
1652 conversions per second via function calls.
183 conversions per second via script executions.

If you compare the performance,  it's down about 10% after the new features added, but I think I can live with that.