Converting seconds to human readable time duration.
td.sh project has two implementations:
C:
The C implementation include
- library (
libtd), - command-line program (
td), and - Bash loadable (
td-bash), loaded astdshell builtin.
- library (
Bash script (
td.sh)
When installing from Git repository, run the following command to initialize required files:
$ autoreconf --installBy default, to install to /usr/local, run:
$ ./configure && make && make installOr to /usr:
$ ./configure prefix=/usr && make && make installOr to your home:
$ ./configure prefix=$HOME/.local && make && make installTo uninstall, use uninstall target.
--disable-bash- do not build Bash implementation
--disable-c- do not build C implementation
--enable-bash-loadable=BASH_HEADER_PATHbuild Bash loadable
The loadable is installed as
prefix/bin/td.bash, it can be enabled by, as long astd.bashis in$PATH:$ enable -f "$(which td.bash)" td $ td 123
--disable-pythondo not build Python bindings
--disable-python2- do not build Python 2 binding
--disable-python3- do not build Python 3 binding
--without-check- do not run Check unittest
The basic usage:
$ td.sh 123
2 minutes 3 secondsYou can source the Bash script to have print_td function for better performance:
$ source td.sh
$ print_td 123
2 minutes 3 seconds
$ ./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-a- prints all numbers and units even the numbers are zeros.
-p[X]: number padding- prints out like
_1 second(_denotes the space) or-p0for01 secondor07 seconds, default is a space . -P: unit string padding- prints out like
1 minute 12 seconds, note there is additional space afterminute.
The unittest is done by Check and Autotest:
$ make check$ make benchmarkHere is a sample result of benchmarking:
| conversions | benchmark |
|---|---|
| 2,060 | td.sh function calls |
| 184 | td.sh script executions |
| 60 | td command executions |
| 24,092 | td.bash loadable executions |
| 40 | Python 2 script executions |
| 16 | Python 3 script executions |
This project is licensed under the MIT License, see COPYING for full text:
Copyright (c) 2010, 2012, 2014 Yu-Jie Lin